簡體   English   中英

與mongoskin有關的safe:true和safe:false有什么區別? 以及如何使用?

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

我與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}向您保證僅在插入完成后才執行回調函數,而{safe:false}不保證這樣做。 我始終使用{safe:true},只是為了確保我擁有最新的數據庫版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM