如何仅从主数据库执行读取操作 [英] How to perform read operations from primary only

查看:66
本文介绍了如何仅从主数据库执行读取操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将Mongo DB用于基于Java Java EE的应用程序.我们正在使用一个主数据库和两个辅助数据库作为Mongo DB集群的一部分作为我们体系结构的一部分,Mongo数据库不断地被读取/更新/写入.

We are using Mongo DB for our Java Java EE based application. We are using one primary and two secondary as part of cluster of Mongo DB The Mongo DB is continuously read / Updated / Write as part of our architecture.

由于这个原因,当我们从Mongo DB进行提取操作时,我们得到了脏读(零值).

Due to this we are getting Dirty Reads ( zero values ) When we do a fetch operation from Mongo DB.

为了解决这个问题,我试图以一种方式配置它,使读操作始终从主数据库本身获取,并且写入/更新可以转到主数据库/辅助数据库.

TO solve this, I am trying to configure it in such a way that the read operation always fetches from primary itself and writes / updates can go to primary / secondary.

请告诉我这是否可行(始终从主数据库读取数据,并使用主/辅助数据库中的任何内容进行写入/更新)

Please let me know if this is possible (always read from primary and use any thing primary/secondary for write/update)

这样的设计会对它产生负面影响吗?

And will it have any negative impact with such a design?

推荐答案

由于mongoDB在插入文件中使用分段写入,因此即使在单个节点中,写入操作也可能会滞后. http://docs.mongodb.org/manual/reference/glossary/#term-新闻

Due to mongoDB uses staged writing in inserts, you can have lag in write operations even in a single node. http://docs.mongodb.org/manual/reference/glossary/#term-journal

使用写关注来避免问题(数据不干净): http://api.mongodb.org/java/2.6/com/mongodb/WriteConcern.html

Use write concern to avoid problems (with dirty data): http://api.mongodb.org/java/2.6/com/mongodb/WriteConcern.html

您可以阅读有关写操作的更多信息: http://docs.mongodb.org/manual/core/write-operations/

You can read more about write operations: http://docs.mongodb.org/manual/core/write-operations/

其中指出,不建议在生产中使用无错误检查的写操作.

Which states that using writes without error check is not recommended for production.

这篇关于如何仅从主数据库执行读取操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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