0

I've been using MongoDB (3.2.9) replication for years and barely know the detail how it works. My Stack is Rails 4.2.5 with Mongoid 5.1.3. I've 3 database servers, let's call them A (Primary), B (Secondary) & C (Secondary). My Mongoid configuration as follow:

production: clients: default: database: db_production hosts: - A:27017 - B:27017 - C:27017 options: pool_size: 10 timeout: 60 replica_set: my_replset options: raise_not_found_error: false

What I thought for years, server A is only for write and B+C for read only operation. But when I check on the doc lately (https://docs.mongodb.com/v3.2/replication/), it show that server A is doing write & read while B & C get the copy from A.

So my questions is: How to make sure if B & C serving a 'read' operation to any request? I'm afraid all the requests hitting the server A while B & C are exists just for backup failover.

thanks for any feedback

1

You can play with read preference modes. Basically this will instruct your application to read from secondary members of the replica set. The default behaviour is to read from primary. Be aware that if you use asynchronous replication, data in the secondary may not reflect the most recent write operations.

More details here: https://docs.mongodb.com/manual/core/read-preference/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.