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

findOneAndUpdate and update insert objects instead of arrays despite using array indexes in paths

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL

       

      this.service.db.collection(this.config.mongodb.collections.campaigns)    
      .findOneAndUpdate({ 'metadata.campaign_id''123' }, { $set: 
              {
                  'status.type.0.documentOne': {
                      in_sync: true            
                   },
                   'status.type.0.documentTwo': {
                      in_sync: false   
                   }
               }
           }
      );

      The above code will create `status.type` as an `Object`, whereas this command when run in a shell:

      db.getCollection('campaigns').findOneAndUpdate({ 'metadata.campaign_id''123' },
          $set: {    'status.type.0.documentOne': {        in_sync: true    },
          'status.type.0.documentTwo': {        in_sync: false    }})

      Will create `status.type` as an Array.

       

      db.isMaster() results: 

       

      {
          "ismaster" : true,
          "maxBsonObjectSize" : 16777216,
          "maxMessageSizeBytes" : 48000000,
          "maxWriteBatchSize" : 100000,
          "localTime" : ISODate("2019-11-25T22:15:38.241Z"),
          "logicalSessionTimeoutMinutes" : 30,
          "connectionId" : 405472,
          "minWireVersion" : 0,
          "maxWireVersion" : 8,
          "readOnly" : false,
          "ok" : 1.0
      }

       

       
       
       

            Assignee:
            carl.champain@mongodb.com Carl Champain (Inactive)
            Reporter:
            rd1982rd@gmail.com R D
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: