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

Incorrect insertedIds in response

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.1.2
    • Component/s: None
    • Labels:
    • Environment:
      Mac OSX 10.10.5
      mongodb 3.1.7
      node-mongodb-native 2.1.2
      nodejs 4.1.0

      The response of `db.collection.insert` have malformed `insertedIds` properties.

      Here is a sample of what I got:

      ```
      { result:

      { ok: 1, n: 1 }

      ,
      ops:
      [

      { name: 'team1', status: 'running', _id: 567c09f017e825c31ee849da }

      ],
      insertedCount: 1,
      insertedIds: [ [ '0' ], 567c09f017e825c31ee849da ] }
      ```

      And I traced down the source code, I found a possible reason for this result.

      1. The bulkWrite function already maps the raw response to an object with index being the key and object id being the value. https://github.com/mongodb/node-mongodb-native/blob/2.0/lib/collection.js#L605
      2. In insertMany which invoked by insert, mapInInsertManyResult is called. https://github.com/mongodb/node-mongodb-native/blob/2.0/lib/collection.js#L486
      3. As for mapInInsertManyResult, the same mapping happens again. https://github.com/mongodb/node-mongodb-native/blob/2.0/lib/collection.js#L411

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            RobinQu Robin Qu [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: