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

Can create invalid dbref using $unset, but not $set

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.5.10
    • Affects Version/s: None
    • Component/s: Write Ops
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Query 2017-07-10

      We disallow creating an invalid dbref using $set:

      > db.coll.update({}, {$set: {a: {$ref: "c", $db: "test"}}})
      WriteResult({
      	"nMatched" : 0,
      	"nUpserted" : 0,
      	"nModified" : 0,
      	"writeError" : {
      		"code" : 55,
      		"errmsg" : "The DBRef $ref field must be following by a $id field"
      	}
      })
      

      But it is allowed using $unset:

      > db.coll.insert({a: {$ref: "c", $id: 0, $db: "test"}})
      WriteResult({ "nInserted" : 1 })
      > db.coll.update({}, {$unset: {"a.$id": true}})
      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
      > db.coll.find()
      { "_id" : ObjectId("594d2381ae497a9bea475a71"), "a" : { "$ref" : "c", "$db" : "test" } }
      

            Assignee:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Reporter:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: