-
Type: New Feature
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Write Ops
-
None
Currently, mongoDB server creates object/hash by default during new record/element insertion when using dotted sub-paths inside $set:{} command:
collection.update( { <search.filter> }, { {$set:{"doc.1":{<doc-data>}} }, { safe:true, upsert:true}, function(err, ...
In this case, the following record is created:
{ "_id":<XXX>, ... , "doc" :
}
However, if the record is already created with doc=[] (array) element then the above update leads to an array update procedure.
MongoDB server should not desire by default that the doc is an object {} during record/element creation, because it can be an array too. Please add a new option like "CreateArrayOnInsert:true" so mongoDB server can create arrays[] if the element/record doesn't exist, like this:
collection.update( { <search.filter> }, { {$set:{"doc.1":{<doc-data>}} }, { safe:true, upsert:true, CreateArrayOnInsert:true}, function(err, ...
-> this should create a record with the following elements:
{ "_id":<XXX>, ... , "doc" : [ null, <doc-data> ] }- duplicates
-
SERVER-13478 Resolve ambiguity of positional array updates when the path does not exist
- Backlog