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" } }
- depends on
-
SERVER-29162 UpdateNode implementation should only validate modified fields
- Closed
- is related to
-
SERVER-29831 Can create invalid dbref using insert
- Backlog