Skip to content

Instantly share code, notes, and snippets.

@watson
Created April 10, 2013 20:04
Show Gist options
  • Select an option

  • Save watson/5357966 to your computer and use it in GitHub Desktop.

Select an option

Save watson/5357966 to your computer and use it in GitHub Desktop.
This code will result in 9 "E11000 duplicate key error index" errors
var dbUri = '...';
var db = require('mongojs').connect(dbUri, ['testing']);
var data = { foo: 1 };
for (var n = 0; n < 10; n++) {
db.testing.insert(data, function (err, res) {
if (err) console.log(err.message);
});
}
@watson
Copy link
Copy Markdown
Author

watson commented Apr 10, 2013

The issue seems to be that mongojs adds an _id attribute to the data object, which is then reused after the first insert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment