Allow arrays creation during new record upsert when specifying dotted sub-paths inside $set:{} command

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Duplicate
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Write Ops
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • 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" :

      { "1" : <doc-data> }

      }

      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> ] }

              Assignee:
              Carl Champain (Inactive)
              Reporter:
              Maximus N/A
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: