【发布时间】:2017-07-07 16:45:32
【问题描述】:
我在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:toor@127.0.0.1:27017/cordoba",{safe:true});
db.collection('usuarios').insert(campos,{new:true}, function(err, result)
但我不确定这是否是一个安全:真实的连接,所以我这样放
var db = mongo.db("root:toor@127.0.0.1:27017/cordoba",{safe:true});
db.collection('usuarios').insert(campos,{safe:true},{new:true}, function(err, result)
可能这样是安全的:true 但是当我将 safe:true 放在 new:true 之前 mongodb 会返回旧的 var,所以我将 safe:true 放在 new:true 之后
var db = mongo.db("root:toor@127.0.0.1:27017/cordoba",{safe:true});
db.collection('usuarios').insert(campos,{new:true},{safe:true}, function(err, result)
并且工作正常,但我不确定它是否安全:true,所以我尝试将 safe:true 放入 new:true 对象中
var db = mongo.db("root:toor@127.0.0.1:27017/cordoba",{safe:true});
db.collection('usuarios').insert(campos,{new:true,safe:true},function(err, result)
我以为 mongdb 吓坏了!但是什么都没有...没有错误没有什么...所以我不知道我怎么知道mongodb何时使用安全:真或不安全:真...
我怎么知道?
【问题讨论】:
标签: javascript node.js mongodb mongoskin nosql