Node.jsネイティブドライバーを使用しています。以下は正常に動作します
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();
});
});
私はデータベースで次のものを取得します
{"hello": "world_safe"、 "_id":ObjectId( "4fe978c8b8a5937d62000001")} {"hello": "world_safe"、 "_id":ObjectId( "4fe978c8b8a5937d62000002")}
しかし、私が次のように微調整すると
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();
});
});
次のエラーが発生します
MongoError:E11000重複キーエラーインデックス:
エラーメッセージが表示されるのはなぜですか?