首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何知道连接是否安全可靠?

如何知道连接是否安全可靠?
EN

Stack Overflow用户
提问于 2013-02-21 14:03:16
回答 1查看 316关注 0票数 0

我在mongodb上提出了很多关于连接的问题,我还不能理解很多东西,但我尝试着……

通过这种连接..。

代码语言:javascript
复制
db.collection('usuarios').insert(campos,{safe:true}, function(err, result)

我得到了一个安全的连接...但是mongodb给我发了这个警告

代码语言:javascript
复制
========================================================================================
=  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           =
========================================================================================

所以我试着这样..。

代码语言:javascript
复制
var db = mongo.db("root:toor@127.0.0.1:27017/cordoba",{safe:true});
db.collection('usuarios').insert(campos,{new:true}, function(err, result)

但是我不确定这是否是一个安全的:真正的连接,所以我这样写

代码语言:javascript
复制
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之后

代码语言:javascript
复制
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对象中,如下所示

代码语言:javascript
复制
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…

我怎么知道??

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-21 15:11:55

接口不再是{safe: true},而是{w: 1} http://mongodb.github.com/node-mongodb-native/api-generated/db.html

代码语言:javascript
复制
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}选项。

所以基本上,你不需要设置任何选项(在插入时)。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14995602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档