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)

その方法はsafe:trueかもしれませんが、new:trueの前にsafe:trueを置くと、mongodbは古​​い変数を返すので、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)

正しく動作しますが、safe:trueかどうかわからないので、このような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)

私はmongdbがおかしいと思った!しかし、何も...エラーも何も....だから、mongodbがsafe:trueまたはnot safe:trueを使用していることをどうやって知ることができるのかわかりません...

どうすればそれを知ることができますか?

4

1 に答える 1

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}引き続き機能しますが、非推奨です。DBレベルで設定する場合は、そのcollection.insert()レベルで設定する必要はありません。

挿入のAPI署名はinsert(docs[, options][, callback])であるため、オプションオブジェクトは1つだけにする必要があります。

また、の{new: true}オプションはありませんcollection.insert

したがって、基本的に、(挿入時に)オプションを設定する必要はありません。

于 2013-02-21T07:11:55.383 に答える