Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-83085

Upsert from $nor predicate generates different fields

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • Hide
       MongoDB Enterprise > db.runCommand({
      update: "coll",
      updates: [{
      multi: true,
      upsert: true,
      q: {
      $nor: [{
      $or: [
      { "x": 1 }
      ,
      { "y": 2 }
      ]
      }, {
      "x":
      { $ne: 3 }
      }]
      },
      u: [ { "$unset" : "z" } ]
      }]
      })
      {
      "n" : 1,
      "upserted" : [
      { "index": 0, "_id": ObjectId("654d421587d21e4fb0f54e2e") }
      ],
      "nModified" : 0,
      "ok" : 1
      }
      MongoDB Enterprise > db.coll.find()
      { "_id" : ObjectId("654d421587d21e4fb0f54e2e"), "x" : 3 }

       

      Show
      MongoDB Enterprise > db.runCommand({ update: "coll" , updates: [{ multi: true , upsert: true , q: { $nor: [{ $or: [ { "x" : 1 } , { "y" : 2 } ] }, { "x" : { $ne: 3 } }] }, u: [ { "$unset" : "z" } ] }] }) { "n" : 1, "upserted" : [ { "index" : 0, "_id" : ObjectId( "654d421587d21e4fb0f54e2e" ) } ], "nModified" : 0, "ok" : 1 } MongoDB Enterprise > db.coll.find() { "_id" : ObjectId( "654d421587d21e4fb0f54e2e" ), "x" : 3 }  
    • QO 2024-02-05

      I ran into this while adding upsert support to the update fuzzer during skunkworks (TIG-4521). This appears to be caused by SERVER-81630 - I noticed different behavior after it than before it. Before the change, an upsert with a query like this:

      {$nor: [{$or: [{x: 1}, {y: 2}]}, {x: {$ne: 3}}]} 

      would insert an empty document (that is, empty aside from _id). After the change, it inserts a document with _id and a field from the $nor predicate (x: 3). This predicate with a $ne and $or nested in a $nor was the simplest one I could find to trigger the differing behavior.

            Assignee:
            bernard.gorman@mongodb.com Bernard Gorman
            Reporter:
            alyssa.clark@mongodb.com Alyssa Clark
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: