简体   繁体   中英

How do we connect to only Primary Set when connected to MongoDB replica set using connection string?

We configured MongoDB replica set in Ubuntu server with two secondary set. When we try to connect to replica set via mongo shell. It is connecting to secondary. We should make sure that it should only connected to Primary set. connection string we tried: mongo 'mongodb://publicIP1:27017,publicIP2:27017,publicIP3:27017/?replcaSet=rs123'

See this doc: https://docs.mongodb.com/manual/core/read-preference/ . The connection string will look like: "mongodb://localhost?readPreference=primary"

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