简体   繁体   中英

“Secondary” vs “Slave” in Mongodb

I am trying to clarify the terminology difference, if any, between "Secondary" and "Slave" in mongodb.

Confusion stems from connecting w/ the node-mongodb-native documentation of the Db constructor :

db_opts = {db: {
   readPreference: ReadPreference.SECONDARY
   slaveOk: true 
}}

MongoClient.connect('mongodb://example', db_opts, ...)

What is the difference between the readPreference option and the slaveOk option there?

Don't get caught up on Secondary vs. Slave here. What you're really asking is about slaveOk vs readPreference.

slaveOk is essentially deprecated in favor of using readPreference . The MongoClient docs do explicitly state for slaveOk: "legacy option allowing reads from secondary, use readPrefrence instead". They also state that setting a readPreference overrides any slaveOk value.

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