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

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

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Write Ops
    • Labels:
      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@mongodb.com Carl Champain (Inactive)
            Reporter:
            maxbanin79@gmail.com Maximus N/A
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: