1

我与 mongoskin 和 nodejs 有联系:

var db = mongo.db("root:toor@127.0.0.1:27017/cordoba");

但我不知道在这种情况下哪个是最佳做法......

db.collection('usuarios').insert(campos,{safe:true}, function(err, result)

我想在 mongodb 中插入 campos,我使用的是 safe:true ......那么如果我使用 safe:false 会发生什么,最佳实践是什么?

这:

 var db = mongo.db("root:toor@127.0.0.1:27017/cordoba");
 db.collection('usuarios').insert(campos,{safe:true}, function(err, result)

或这个:

var db = mongo.db("root:toor@127.0.0.1:27017/cordoba",{safe:true});
db.collection('usuarios').insert(campos, function(err, result)
4

1 回答 1

1

{safe:true} 保证回调函数只有在插入完成后才会执行,而 {safe:false} 不保证这一点。我总是使用 {safe:true},只是为了确保我拥有最新版本的数据库。

于 2013-02-26T18:21:35.023 回答