与mongoskin关联的safe:true和safe:false有什么区别?以及如何使用? [英] What is the difference between safe:true and safe:false in a connection with mongoskin? and how use it?

查看:187
本文介绍了与mongoskin关联的safe:true和safe:false有什么区别?以及如何使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与mongoskin和nodejs有联系:

I have a connection with mongoskin and nodejs:

var db = mongo.db("root:toor@127.0.0.1:27017/cordoba");

但是我不知道在这种情况下哪种是最佳做法...

but I don't know which is the best practice in this case...

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

我想在mongodb中插入campos,我使用的是safe:true ...那么,如果我使用safe:false会发生什么,最佳实践是什么?

I want to insert campos in mongodb, I'm using safe:true... so what happens if I use safe:false, and what is the best practice?

此:

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

或者这个:

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

推荐答案

{safe:true}向您保证,仅在插入完成后才执行回调函数,而{safe:false}不保证这样做.我始终使用{safe:true},只是为了确保我拥有最新的数据库版本.

{safe:true} assures you that the callback function will get executed only after the insertion is done and {safe:false} does not guarantee that. I always use {safe:true}, just to make sure that I have the most up to date version of the DB.

这篇关于与mongoskin关联的safe:true和safe:false有什么区别?以及如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆