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: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 但是当我在 new:true 之前放置 safe:true 时,mongodb 会返回旧的 var,所以我在 new:true 之后放置了 safe: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)

我以为 mondb 吓坏了!但是什么都没有...没有错误没有什么...所以我不知道我怎么知道mongodb何时使用安全:真或不安全:真...

我怎么知道??

4

1 回答 1

3

the api is no longer {safe: true} but {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} will still work, but it's deprecated. if you set it at the DB level, you don't need to set it at the collection.insert() level.

the api signature for insert is insert(docs[, options][, callback]), so you should only have one options object.

also, there is no {new: true} options for collection.insert.

so basically, you don't need to set any options (on insert).

于 2013-02-21T07:11:55.383 回答