Mongodb – Mongo DB Replica set – not able to read also

mongodbmongodb-3.0

We have deployed mongodb replica set:

mongod --port 27017   --dbpath /opt/eltropy/mongodb/data/rs0-1 --replSet rs0 --smallfiles --oplogSize 128

mongod --port 27018   --dbpath /opt/eltropy/mongodb/data/rs0-1 --replSet rs0 --smallfiles --oplogSize 128

mongod --port 27019   --dbpath /opt/eltropy/mongodb/data/rs0-1 --replSet rs0 --smallfiles --oplogSize 128

What I understand from mongdb documentation; even if your two nodes goes down, we still should be able to read from remaining working nodes (Single working node in this case). However, write is not possible.

But even reads are not working on the available node. I also try to add one arbiter but still no luck. Remaining node still stay in secondary stage.

I am using mongodb 3.0.

Best Answer

The reason

The answer is quite simple: when two voting nodes of three are down, the remaining one reverts to secondary, to which – by definition – one can't write. The default read preference is to read from and write to the primary of a replica set only. Hence, when only a secondary remains in the replica set, you can not read.

tl;dr

You have to change your read preference at least to primaryPreferred, allowing reads from secondaries.