godo57
godo57

Reputation: 548

Set mongodb read preference at mongo server level

I have one PRIMARY instance and one SECONDARY instance of mongodb.

Many clients are using my two instances. Each client has its own read preference to "secondary" My question is : Is there a way to configure mongodb to set by default the read preference to "secondary" ?

Thanks

MC

Upvotes: 3

Views: 605

Answers (1)

mnemosyn
mnemosyn

Reputation: 46281

Read preference is a client setting, not a server setting, so no, this is not possible as far as I know. An important feature of MongoDB is that you have very fine-grained control over the queries, i.e. you can use different read preferences and write concerns for each query.

It often makes sense to mix these, because losing a log entry might not be too bad while losing a payment is. Likewise, reading logs from the secondary might be fine, but if you want to coordinate a transaction, it might be safer to use the primary for reading (or you're using a paranoid write concern that requires full replication before considering the write successful).

Upvotes: 3

Related Questions