I am working with NodeJS and MongoDB and on start I create collections and fill them in if they don't already exist. Right now this is just development , but with backups and things I could end up doing the same thing or something similar in production.
My question is what will happen to the iteration variable(i
)? Will the callback use the correct value for that iteration? Or will it get some other value further down the list, or perhaps none at all?
ldb.createCollection('people', { strict: true }, function(err, col){
if(err) { console.log('createCollection( people ) ', err); }
else {
for(var i in people){
col.insert(people[i], { w: 1 }, function(err, doc){
people[i]._id = doc._id;
}
}
}
});
Edit: This is an object, not an array.