After installing mongodb, I ran mongod
with
mongod --dbpath <pathtodb> --logpath <pathtolog> --replSet rs0
I then connected with the mongo shell and ran
rs.initiate()
I then tried to insert a document into a collection, but received an error:
> db.blah.insert({a:1})
WriteResult({ "writeError" : { "code" : undefined, "errmsg" : "not master" } })
Looking at rs.status()
, I see the status is REMOVED
:
> rs.status() { "state" : 10, "stateStr" : "REMOVED", "uptime" : 1041, "optime" : Timestamp(1429037007, 1), "optimeDate" : ISODate("2015-04-14T18:43:27Z"), "ok" : 0, "errmsg" : "Our replica set config is invalid or we are not a member of it", "code" : 93 }
I have no idea what I could have done to mess this up. This should have worked I think. How do I get past this?
Problem here is that you ran rs.initiate()
.. As EMPTY! You didn't tell what machines belongs to that replica set.
So..
rs.initiate({
_id: "rs0",
version: 1,
members: [
{ _id: 0, host : "address.to.this.machine:27017" }
]
}
)