christkv/node-mongodb-native — Issue #494: insert-callback returns wrong objects
Author: itsatony
Created: 2012-02-02 20:40:25+00:00
State: open

my Problem: i insert documents and i need to get the inserted document back.
i do not supply a pre-made _id for the documents to insert.
whenever there are multiple inserts in quick succession (multiple users, one quick user, ...) in the insert callback i get (often, but, not always) the same object (always the one from the earlier insert).

i have the following code (imagine calls are parallel from many users):

´´´
function insertTheDamnObject(newObject) {
console.log(newObject.title);
mongoDB.collection.insert(
newObject,
{safe:true},
function(errors, insertedObject) {
console.log(newObject._id);
});
}

newObject = {
title: 'a'
};

newObject2 = {
title: 'b'
}
insertTheDamnObject(newObject1);
insertTheDamnObject(newObject2);
```

--> console:
a (before insert)
4f2af232a024581164000054 (from inside the insert.callback)
b (before insert)
4f2af232a024581164000054 (from inside the insert callback)