Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1125

Bulk find and update returns nUpserted instead of nModified

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.30
    • Component/s: MongoDB 3.4
    • Environment:
      Mac OS 12.10.6

      Note: I'm filing on behalf on Mixmax, which has an enterprise support contract.

      The following bulk update operation:

      bulk.find({
        _id: userId,
        stages: {
          $elemMatch: {
            id: stageId
          }
        }
      })
      .update({
        $set: {
          'stages.$.scheduledAt': date
        }
      });
      

      produces the WriteResult

      { writeErrors: [],
        writeConcernErrors: [],
        nInserted: 0,
        nUpserted: 99,
        nMatched: 0,
        nModified: 0,
        nRemoved: 0,
        upserted: [],
        ok: 1 }
      

      However, the collection in question contains the same number of records before and after the operation runs. The records are successfully modified by the operation, but it does not appear that an upsert is occuring - nor is one desired. (Note the absence of a .upsert() call on the operation - should upserting even be possible?) Furthermore, the (undocumented?) "upserted" array on the writeresult object is empty, which would also seem to indicate no upserting occurred.

      Why is nUpserted being used instead of nModified?

            Assignee:
            Unassigned Unassigned
            Reporter:
            logandavis Logan Davis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: