安全性如何MongoDB的在插入安全模式? [英] How safe is MongoDB's safe mode on inserts?

查看:230
本文介绍了安全性如何MongoDB的在插入安全模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作有它的一些重要数据的项目。这意味着我们可以不失去任何它如果光或服务器宕机。我们使用的MongoDB数据库。我想确保我的数据是在插入后,数据库和回滚整批如果一个元素没有被插入。我知道这是蒙戈背后的经营理念,我们并不需要交易,但我怎么能保证我的数据是真正安全地插入,而不是发送到某些黑洞后保存。

I am working on a project which has some important data in it. This means we cannot to lose any of it if the light or server goes down. We are using MongoDB for the database. I'd like to be sure that my data is in the database after the insert and rollback the whole batch if one element was not inserted. I know it is the philosophy behind Mongo that we do not need transactions but how can I make sure that my data is really safely stored after insert rather than sent to some "black hole".


  • 我应该做一个搜索?

  • Should I make a search?

我应该使用一些特定的MongoDB的命令?

Should I use some specific mongoDB commands?

我应该使用分片即使一台服务器就足够了令人满意的结果
速度和它的方式并不能保证什么,如果光结果
下山?

Should I use sharding even if one server is enough for satisfying
the speed and by the way it doesn't guarantee anything if the light
goes down?

什么是最好的解决方案?

What is the best solution?

推荐答案

您最好的选择是用写的担忧 - 这些让你告诉MongoDB的一个数据是多么的重要。最快写入关注也是最安全的 - 数据不刷新到磁盘上,直到下一个预定平齐。最安全的将确认返回前数据已被写入到一个数量的机器上。

Your best bet is to use Write Concerns - these allow you to tell MongoDB how important a piece of data is. The quickest Write Concern is also the least safe - the data is not flushed to disk until the next scheduled flush. The safest will confirm that the data has been written to disk on a number of machines before returning.

您正在寻找的写关注的是FSYNC_SAFE(至少这是它是从看的Java司机)或REPLICAS_SAFE这证实您的数据已被复制。

The write concern you are looking for is FSYNC_SAFE (at least that is what it is called from the point of view of the Java driver) or REPLICAS_SAFE which confirms that your data has been replicated.

请记住MongoDB中没有传统意义上的交易 - 你回滚将不得不用手卷起因为你不能告诉Mongo的数据库来为你做这个

Bear in mind that MongoDB does not have transactions in the traditional sense - your rollback will have to be rolled by hand as you can't tell the Mongo database to do this for you.

您需要做的另一件事是要么使用较新的 - 期刊选项(它使用预写日志),或使用副本集共享数据多台机器,以最大限度地崩溃/掉电的情况下,数据的完整性。

The other thing you need to do is either use the relatively new --journal option (which uses a Write Ahead Log), or use replica sets to share your data across many machines in order to maximise data integrity in the event of a crash/power loss.

分片与其说是针对硬件故障保护作为与特别大的数据集打交道时分担负载的方法 - 分片不能与副本集是写数据的方法到多个磁盘上更多的混淆一机多用。

Sharding is not so much a protection against hardware failure as a method for sharing the load when dealing with particularly large datasets - sharding shouldn't be confused with replica sets which is a way of writing data to more than one disk on more than one machine.

因此​​,如果你的数据是足够有价值,你绝对应该以提供您需要的韧性使用副本集,甚至选址奴隶其他数据中心/可用性区域/机架/等。

Therefore, if your data is valuable enough, you should definitely be using replica sets, perhaps even siting slaves in other data centres/availability zones/racks/etc in order to provide the resilience you require.

有是/会(不记得是否副手这已经尚未实现)的方式来指定设置这样的副本各个节点的优先级,如果主下山即选举产生了新主人是一家在同一个数据中心,如果这样的机器是可用的(即成为高手,除非它真的是唯一的选择停在该国的另一侧的奴隶)。

There is/will be (can't remember offhand whether this has been implemented yet) a way to specify the priority of individual nodes in a replica set such that if the master goes down the new master that is elected is one in the same data centre if such a machine is available (ie to stop a slave on the other side of the country from becoming master unless it really is the only other option).

这篇关于安全性如何MongoDB的在插入安全模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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