I have a MongoDB DB X sharded in 2 replica set. Now I want to add a replica (which will be only read operations) to reduce load on mongodb for reporting purpose.
How is possible to achieve this as my collections are sharded to 2 different replica sets?
Mongodb – Add a mongodb read only replica for reporting purpose
mongodbmongodb-3.2
Related Question
- Mongodb – Unable to add replica set to shard
- Mongodb – Mobile node in a mongodb replica set
- Mongodb – Could not add Replica Set to MongoDB Shard
- Mongodb – Create Replica Sets on an existing sharded MongoDB
- MongoDB – overloading PRIMARY with multiple replica set
- Mongodb – How to properly connect a replica set to split write and read with ApsaraDB for MongoDB
- Mongodb: Can I create an unshard Replica set for a sharded cluster
Best Answer
Sharding a Mongo DB should not have any impact on your readable secondaries. Each shard will have a replica set just as if it wasn't sharded. The 'read only' methods to access those would be the same way.
https://docs.mongodb.com/manual/core/read-preference-mechanics/ From the link:
Read Preference and Shards
For sharded clusters that have replica set shards, mongos applies the read preference when reading from the shards. Server selection is governed by the read preference and replication.localPingThresholdMs settings.
You're probably going to look for the 'secondary preferred' option: https://docs.mongodb.com/manual/reference/read-preference/#secondaryPreferred
"In most situations, operations read from secondary members, but in situations where the set consists of a single primary (and no other members), the read operation will use the set’s primary. When the read preference includes a tag set, the client attempts to find a secondary member that matches the specified tag set and directs reads to a random secondary from among the nearest group. If no secondaries have matching tags, the client ignores tags and reads from the primary. Read operations using the secondaryPreferred mode may return stale data."