MongoDB的,重复和错误:{" $ ERR" :"没有掌握和slaveOk =假QUOT;," code" :13435} [英] mongodb, replicates and error: { "$err" : "not master and slaveOk=false", "code" : 13435 }

查看:696
本文介绍了MongoDB的,重复和错误:{" $ ERR" :"没有掌握和slaveOk =假QUOT;," code" :13435}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过蒙戈副本集的第一次。

I tried mongo replica sets for the first time.

我使用的Ubuntu在EC2上,我启动了三个实例。 我用每个实例的私有IP地址。我选上作为主,下方则是code。

I am using ubuntu on ec2 and I booted up three instances. I used the private IP address of each of the instances. I picked on as the primary and below is the code.

mongo --host Private IP Address
rs.initiate()
rs.add("Private IP Address")
rs.addArb("Private IP Address")

所有在这一点上是好的。当我去到<一个href="http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com:28017/_replSet">http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com:28017/_replSet现场我看到,我有一个小学,seconday和arbitor。

All at this point is fine. When I go to the http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com:28017/_replSet site I see that I have a primary, seconday, and arbitor.

好了,现在的测试。

在主创建一个数据库,这是code:

On the primary create a database in this is the code:

use tt
db.tt.save( { a : 123 } )

在二次,然后我做到这一点,并得到了以下错误:

on the secondary, I then do this and get the below error:

db.tt.find()
error: { "$err" : "not master and slaveOk=false", "code" : 13435 }

我很新的MongoDB和重复,但我想,如果我做的东西之一,它转到其他。所以,如果我加入一个记录,我有什么做的机器之间进行复制?

I am very new to mongodb and replicates but I thought that if I do something in one, it goes to the other. So, if I add a record in one, what do I have to do to replicate across machines?

推荐答案

您必须设置从好的模式,让蒙戈外壳知道你允许读取一个次要的。这是为了保护您和您的应用程序的执行最终一致性读取意外。您可以在外壳做到这一点:

You have to set "slave okay" mode to let the mongo shell know that you're allowing reads from a secondary. This is to protect you and your applications from performing eventually consistent reads by accident. You can do this in the shell with:

rs.slaveOk()

之后,你可以从二级正常查询。

After that you can query normally from secondaries.

关于最终一致性的注意事项:在正常情况下,副本集次级具有完全相同的数据,在一秒钟内或更少的初选。在非常高负载,数据你写到主可能需要一段时间来复制到二级。这就是所谓的复制品滞后,并从一个滞后次级被称为最终一致性读读书,因为,而新写入的数据将显示在某点(限制网络故障等),它可能不立即可用。

A note about "eventual consistency": under normal circumstances, replica set secondaries have all the same data as primaries within a second or less. Under very high load, data that you've written to the primary may take a while to replicate to the secondaries. This is known as "replica lag", and reading from a lagging secondary is known as an "eventually consistent" read, because, while the newly written data will show up at some point (barring network failures, etc), it may not be immediately available.

编辑::您只能从二级每个会话查询时,只有一次需要设置slaveok。

You only need to set slaveok when querying from secondaries, and only once per session.

这篇关于MongoDB的,重复和错误:{&QUOT; $ ERR&QUOT; :&QUOT;没有掌握和slaveOk =假QUOT;,&QUOT; code&QUOT; :13435}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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