I use the native Node.js. driver The following works fine
db.collection("test").insert({hello:'world_safe'}, {safe: true}, function(err, result) { if (err) throw err; db.collection("test").insert({hello:'world_safe'}, {safe: true}, function(err, result) { if (err) throw err; db.close(); }); });
I get the following in the database
{"hello": "world_safe", "_id": ObjectId ("4fe978c8b8a5937d62000001")} {"hello": "world_safe", "_id": ObjectId ("4fe978c8b8a5937d62000002")}
However, when I configure as follows
var json = {hello:'world_safe'}; db.collection("test").insert(json, {safe: true}, function(err, result) { if (err) throw err; db.collection("test").insert(json, {safe: true}, function(err, result) { if (err) throw err; db.close(); }); });
I get the following error
MongoError: E11000 duplicate key error index:
Why am I getting an error message?
source share