$merge corrupts field order in some cases on insert.

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Critical - P2
    • None
    • Affects Version/s: 8.0.13
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • Hide

      See above.

      Show
      See above.
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      > db.foo.drop()
      
      db.aggregate([{$documents:[{z: 1, a: 1}]}, {$merge: {into: "foo", whenMatched:"keepExisting", whenNotMatched:"insert"}}])
      
      db.foo.find()
      

      When I run the above I get:

      [ { _id: ObjectId('68baf740fcc543022431a453'), a: 1, z: 1 } ]
      

      Note that `find` shows the `a` field first, even though the aggregation has `z` first.

      Per max.hirschhorn@mongodb.com, this bug is specific to this pair of whenMatched/whenNotMatched settings. It does not happen, for example, if `whenMatched` is `replace`.

      Workaround

      whenMatched: [{$replaceWith: "$$ROOT"}]
      

            Assignee:
            Unassigned
            Reporter:
            Felipe Gasper
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: