本文介绍了mongodb:我应该总是使用'​​安全'选项更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当处理mongodb时,我应该在查询上使用{safe:true}?

when dealing with mongodb, when should i use the {safe: true} on queries?

现在我使用'safe'选项,查询已成功插入或更新。

Right now I use the 'safe' option just to check if my queries were inserted or updated successfully. However, I feel this might be over kill.

我应该假设99%的时间,我的查询(假设它们被正确写入)将被插入/更新,

Should i assume that 99% of the time, my queries (assuming they are properly written) will be inserted/updated, not have to worry about checking if they successfully inputted?

推荐答案

不需要担心检查他们是否成功输入。

解决方案

假设你说查询你实际上意味着写/插入(你的问题的措辞让我认为这),那么写关注(安全,无,fsync等)可以用来获得更多的速度和安全性,当

Assuming when you say queries you actually mean writes/inserts (the wording of your question makes me think this) then the Write Concern (safe, none, fsync, etc) can be used to get more speed and less safety when that is acceptable, and less speed and more safety when that is necessary.

作为一个例子,一个假设的Facebook风格的应用程序可以使用不安全的写作喜欢,而它将使用非常安全的写入密码更改。这背后的逻辑是,将有几千个喜欢 - 样式更新发生一秒,这是没有关系,如果一个丢失,而密码更新发生较少规律,但它是成功的关键。

As an example, a hypothetical Facebook-style application could use an unsafe write for "Likes" while it would use a very safe write for password changes. The logic behind this is that there will be many thousand "Like"-style updates happening a second, and it doesn't matter if one is lost, whereas password updates happen less regularly but it is essential that they succeed.

因此,根据您的速度和数据完整性要求,尝试根据您正在进行的更新调整您的写入问题选择。

Therefore, try to tailor your Write Concern choice to the kind of update you are doing, based upon your speed and data integrity requirements.

这篇关于mongodb:我应该总是使用'​​安全'选项更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 14:41