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

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 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”)

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.

Ok, now for a test.

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 }

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?

9 Answers
9

Leave a Comment