We have two shards rs1 and rs2 at two locations NYC and SFO. We have a gridfs collection that is sharded based on the location. So all the data from NYC go to rs1 and all data from SFO go to rs2 shard. When the rs2 shard becomes read only because majority servers are down, even though the connection string has readPreference=secondary, the gridFS put call fails with error message
Encountered non-retryable error during query :: caused by :: Could not find host matching read preference { mode: “primary” } for set rs2, full error: {‘ok’: 0.0, ‘errmsg’: ‘Encountered non-retryable error during query :: caused by :: Could not find host matching read preference { mode: “primary” } for set rs2’, ‘code’: 133
The data that is being inserted is going to rs1, the shard that has primary node up and running. (I checked the chunks distribution for both fs.files and fs.chunks collections and also inserted the document bringing up rs2 shard and check where the document went.) But I don’t know why it is complaining.
We are using mongodb vesrion 4.0. I tried it on both C# driver and pymongo so it is not the driver issue. Seems like the put implementation has readPreference set to primary.
I tested other collections and they do allow writing when the document goes to rs1 when rs2 is readonly.
I am also planning to move to higher version to see if it has been fixed in later versions. If anyone has already used the GridFS sharding and the inserts are working when one shard is readonly please let me know.