mongodb, replicates and error: { “$err” : “not master and slaveOk=false”, “code” : 13435 }

前端 未结 8 1428
遥遥无期
遥遥无期 2020-11-30 17:24

I tried mongo replica sets for the first time.

I am using ubuntu on ec2 and I booted up three instances. I used the private IP address of each of the instances. I p

相关标签:
8条回答
  • 2020-11-30 17:53

    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.

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

    0 讨论(0)
  • 2020-11-30 18:01

    in mongodb2.0

    you should type

    rs.slaveOk()
    

    in secondary mongod node

    0 讨论(0)
提交回复
热议问题