Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1281

User is getting an error running a bulk command on new MongoShell

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.6.0
    • Affects Version/s: None
    • Component/s: Bulk Operations, Shell API
    • Labels:
      None
    • 3
    • Not Needed
    • Iteration Herring, Iteration Isopod, Iteration Jellyfish, Iteration Kraken

      Problem Statement/Rationale

      User is receiving an error when executing a bulk command on the MongoShell embedded in Compass:

       var bulk = db.mktest.initializeUnorderedBulkOp();
      bulk.find( {"payload.businessContextMetadata.claim": {$exists: true }} ).update([{ $set:
      { "payload.businessContextMetadata.claims": ["$payload.businessContextMetadata.claim"] }
      }]);
      bulk.execute();

      Full error attached.

      Steps to Reproduce

      Connect to an Atlas cluster using MongoShell embedded in Compass or non-embedded version.

      Execute the command in the same order that posted above.

      Expected Results

      The user expects the same results that when executing the command on the Enterprise server:

       MongoDB Enterprise MPODS-DEV-020:PRIMARY> var bulk = db.mktest.initializeUnorderedBulkOp();MongoDB Enterprise MPODS-DEV-020:PRIMARY> bulk.find( {"payload.businessContextMetadata.claim": {$exists: true }} ).update(... [... { $set: { "payload.businessContextMetadata.claims": ["$payload.businessContextMetadata.claim"] } }... ]... );MongoDB Enterprise MPODS-DEV-020:PRIMARY> bulk.execute();BulkWriteResult({"writeErrors" : [ ],"writeConcernErrors" : [ ],"nInserted" : 0,"nUpserted" : 0,"nMatched" : 499802,"nModified" : 499802,"nRemoved" : 0,"upserted" : [ ]})

      Actual Results

      MongoBulkWriteError: multi update is not supported for replacement-style update
      Result:
      { result:
          { ok: 1,
           writeErrors:
             [ { err:
                  { index: 0,
                   code: 9,
                   errmsg: 'multi update is not supported for replacement-style update',
                   errInfo: undefined,
                   op:
                     { q: { 'payload.businessContextMetadata.claim': { '$exists': true } },
                       u: { '0': { '$set':{'payload.businessContextMetadata.claims': [ '$payload.businessContextMetadata.claim' ] } } },
                       multi: true } } } ],
           writeConcernErrors: [],
           insertedIds: [],
           nInserted: 0,
           nUpserted: 0,
           nMatched: 0,
           nModified: 0,
           nRemoved: 0,
           upserted: [],
           opTime: { ts: { low: 1, high: 1658951729, unsigned: true }, t: 101 } } }

      Additional Notes

      UpdateMany() works fine.

      The update operator documentation mention that you cannot specify multi: true when performing a replacement, i.e., when the update document contains only field:value expressions which seems the trigger of this error.

       

      Also error comes from the server as per following documentation]

       

        1. Full error.png
          Full error.png
          375 kB
        2. mongo.js
          1 kB
        3. mongosh.js
          1 kB

            Assignee:
            anna.henningsen@mongodb.com Anna Henningsen
            Reporter:
            alejo.gonez@mongodb.com Alejo Goñez
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: