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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Done
    • None
    • None
    • None
    • None
    • ALL

    Description

       

      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
      }

       

       
       
       

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: