2013-02-21 117 views
0

我有關MongoDB做出有關連接很多次的問題,我無法理解很多東西,但我嘗試...我怎麼知道連接是否安全真實?

與此相關的...

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

我得到一個安全的連接... 。但MongoDB的拉我這個警告

======================================================================================== 
= Please ensure that you set the default safe variable to one of the     = 
= allowed values of [true | false | {j:true} | {w:n, wtimeout:n} | {fsync:true}]  = 
= the default value is false which means the driver receives does     = 
= return the information of the success/error of the insert/update/remove   = 
=                      = 
= ex: new Db(new Server('localhost', 27017), {safe:true})       = 
=                      = 
= http://www.mongodb.org/display/DOCS/getLastError+Command       = 
=                      = 
= The default of false will change to true in the near future       = 
=                      = 
= This message will disappear when the default safe is set on the driver Db   = 
======================================================================================== 

,所以我嘗試這樣...

var db = mongo.db("root:[email protected]:27017/cordoba",{safe:true}); 
db.collection('usuarios').insert(campos,{new:true}, function(err, result) 

但林不知道這是否是安全的:真正的連接,所以我把這樣的

var db = mongo.db("root:[email protected]:27017/cordoba",{safe:true}); 
    db.collection('usuarios').insert(campos,{safe:true},{new:true}, function(err, result) 

正是以這種方式是安全的:真正的,但是當我把安全:真之前新:真正的MongoDB返回我的老VAR,所以我把安全:真後新:真正

var db = mongo.db("root:[email protected]:27017/cordoba",{safe:true}); 
    db.collection('usuarios').insert(campos,{new:true},{safe:true}, function(err, result) 

和工作的權利,但林不知道這是否是安全的:真實的,所以我儘量把安全:真新:真正的對象這樣

var db = mongo.db("root:[email protected]:27017/cordoba",{safe:true}); 
     db.collection('usuarios').insert(campos,{new:true,safe:true},function(err, result) 

我以爲那個星期一gdb嚇壞了!但沒有...沒有錯誤沒有什麼....所以我不知道我怎麼能知道當mongodb使用安全:真或不安全:真...

我怎麼知道?

回答

3

的API不再{safe: true}{w: 1}http://mongodb.github.com/node-mongodb-native/api-generated/db.html

var db = mongo.db('mongodb://127.0.0.1:27017/test', {w: 1}) 

{safe: true}仍然可以工作,但它已過時。如果您將其設置爲數據庫級別,則無需將其設置爲collection.insert()級別。

插入的api簽名是insert(docs[, options][, callback]),所以你應該只有一個選項對象。

此外,collection.insert沒有{new: true}選項。

所以基本上,你不需要設置任何選項(插入)。

+0

好的,謝謝你,再次閱讀api文檔... – andrescabana86 2013-02-21 22:09:28

相關問題