-
Type:
Bug
-
Resolution: Works as Designed
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Test scenario:
db.foo.insertOne({
"name" : "name",
"attr": null
})
db.foo.updateOne(
{name : "name"},
{$set : {"attr.key": "key"}}
)
//com.mongodb.MongoWriteException: Write operation error on server localhost:27017.
// Write error: WriteError{code=28, message='Cannot create field 'key' in element {attr: null}', details={}}.
db.version() // 5.0.2
But documentation for $set says:
If the field does not exist, $set will add a new field with the specified value, provided that the new field does not violate a type constraint. If you specify a dotted path for a non-existent field, $set will create the embedded documents as needed to fulfill the dotted path to the field.