在与mongoskin的联系中,safe:true和safe:false之间有什么区别?以及如何使用它

What is the difference between safe:true and safe:false in a connection with mongoskin? and how use it?

本文关键字:safe 区别 什么 何使用 false 联系 mongoskin 在与 true 之间      更新时间:2023-09-26

我与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)

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