Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-7012

🚨 Switching aggregation pipeline to text view causes it to run!

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 1.40.0
    • Affects Version/s: 1.38.2
    • Component/s: Explain
    • None
    • Environment:
      OS: Mac, m2
      node.js / npm versions: 18.16.0, 9.5.1 (Not sure this is relevant)
      Compass: Version 1.38.2 (1.38.2)
      Additional info:
      Running against CosmosDB v4.2 rather than real Mongo (sorry).
    • 3
    • Needed
    • Hide

      When requesting explain plan for aggregation pipelines, out stages like $merge and $out will be ignored and will not show in explain plan

      Show
      When requesting explain plan for aggregation pipelines, out stages like $merge and $out will be ignored and will not show in explain plan
    • Iteration Juravenator

      Problem Statement/Rationale

      • 🚨 Compass sometimes runs aggregation pipelines without the user clicking 'run'.
      • This puts users at significant risk of running pipelines prematurely, this could easily lead to destroying data unintentionally.
      • (I noticed this bug with a dev db, I have not lost data 🤞🏽)

      Please be sure to attach relevant logs with any sensitive data redacted.
      How to retrieve logs for: Compass; Shell

      Steps to Reproduce

      • Creating an aggregation pipeline using the 'stages' view
      • Add some stages, including a final merge step, back into the original collection
      • Take note of what the intermediate preview docs
      • Click to switch to the text view
      • Click back to the stages view
      • Notice that the pipeline has been executed!
        • I think execution occurs when first clicking to switch to code view, but it is possible it occurs when switching back.
      • I never clicked "Run". There was no confirmation modal.

      Expected Results

      What do you expect to happen?

      Aggregation pipelines are high-risk data transformations. Compass should only run aggregation pipelines after an explicit user action.

      Actual Results

      What do you observe is happening?

      Compass runs aggregation pipelines (including $merge) without the user pressing 'run'.

      Additional Notes

      I have noticed this for several pipelines across the last 1-2 weeks. This when I started using the code view.

      This is one example. Notice that the pipeline filtering docs then altering them so they become excluded from the initial $match. This means that looking at the Compass preview documents it is obvious when the pipeline has been executed because all the previews disappear.

      // Pipeline on a collection called "integrations"
      ```

      [
        {
          $match:
            /**
             * query: The query in MQL.
             */
            {
              roles: {           $exists: false,         },
            },
        },
        {
          $set:
            /**
             * field: The field name
             * expression: The expression.
             */
            {
              roles: [
                {             tenantId: "*",             role: "member",           },
              ],
            },
        },
        {
          $merge:
            /**
             * into: The target collection.
             * on: Fields to  identify.
             * let: Defined variables.
             * whenMatched: Action for matching docs.
             * whenNotMatched: Action for non-matching docs.
             */
            {         into: "integrations",         on: "_id",         whenMatched: "merge",         whenNotMatched: "fail",       },
        }
      ]

      ```

            Assignee:
            sergey.petushkov@mongodb.com Sergey Petushkov
            Reporter:
            jack@healthtech1.uk Jack Newberry
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: