简体   繁体   中英

Mongodb replica set (Write on secondary)

I have created 3 AWS instances for mongodb. One for primary, one for secondary and one arbiter. My application is pointing to the Primary node. So when the Primary goes down and becomes Secondary no data is posted on it. How can I enable write operations for a secondary node. Mongodb's write concern (w:"majority") didnt work for me. Can anyone please give a work around ?

You cannot write on a secondary node.

If you primary goes down, it will become a secondary which will receive the writes through the replication mechanism from the new elected primary (only one machine of yours can be as the other member is an arbiter which doesn't hold data).

Write concern is not about writing to secondaries directly. It is about how many replica set member (primary, secondaries...) have to acknowledge the write for you application to receive the ok from the driver.

Seems like it will work if you don`t connect on the primary direction, but with the name of the replica set as a prefix. If the primary has been restarted and is a secondary now, it will redirect you to the new primary.

If your primary is mongo1 and your replica set is named rs you don`t use

mongo --host mongo1:27017

but

mongo --host rs/mongo1:27017

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM