未加星标

how can i know if connection is safe true?

字体大小 | |
[数据库(综合) 所属分类 数据库(综合) | 发布者 店小二05 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

i made many times questions about connections on mongodb, i cant understand many things yet, but i try...

with this connection...

db.collection('usuarios').insert(campos,{safe:true}, function(err, result)

i get a safe connection.... but mongodb pull me this warning

======================================================================================== = 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 = ========================================================================================

so i try this way...

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

but im not sure if this is a safe:true connection so i put like this

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)

may be that way is safe:true but when i put safe:true before new:true mongodb returns me the old var, so i put safe:true after 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)

and works right but im not sure if it is safe:true, so i try put safe:true in new:true object like this

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)

i thought that mongdb freaks out! but nothing... no error no nothing .... so i dont know how can i know when mongodb is using safe:true or not safe:true...

how can i know that??

Problem courtesy of: andrescabana86

Solution

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).

Solution courtesy of: Jonathan Ong

本文数据库(综合)相关术语:系统安全软件

代码区博客精选文章
分页:12
转载请注明
本文标题:how can i know if connection is safe true?
本站链接:https://www.codesec.net/view/621038.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(综合) | 评论(0) | 阅读(49)