-
Type: Bug
-
Resolution: Done
-
Priority: 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
-
Empty show more show less
The response of `db.collection.insert` have malformed `insertedIds` properties.
Here is a sample of what I got:
```
{ result:
,
ops:
[
],
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