我在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什么时候在使用safe:true或not safe:true…
我怎么知道??
发布于 2013-02-21 15:11:55
接口不再是{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}仍然可以工作,但它已被弃用。如果在DB级别设置它,则不需要在collection.insert()级别设置它。
insert的接口签名是insert(docs[, options][, callback]),所以您应该只有一个options对象。
此外,collection.insert没有{new: true}选项。
所以基本上,你不需要设置任何选项(在插入时)。
https://stackoverflow.com/questions/14995602
复制相似问题