MongoDB brought a lot of innovation to the database ecosystem.
One of this innovation is the concept of a hidden replica set member.
A hidden replica set is a member that keeps a copy of primary's data set, but it is invisible for the client.
This means that this member won't receive any read when the client is connect using the replica set connection string.
Use Cases for the Hidden Replica set member
You can do the backup in production from the hidden member without causing any performance issues to your production workflow.
You can connect your BI (Business Intelligence) to the hidden member, doing a lot of heavy queries without compromising your production workflow .
You can create a new index from a big collection in the hidden member, so you can create the index faster.
Configuring a Hidden Replica Set member
Use mongosh
to connect to a MongoDB node
mongosh mongodb://mongo1:27017,mongo2:27017/db?replicaSet=rs0
Run rs.status()
to see what node is a SECONDARY
rs.status()
Example output:
members: [
{
_id: 0,
name: 'mongodb1:27017',
stateStr: 'PRIMARY',
},
{
_id: 1,
name: 'mongodb2.mongo-prd:27017',
stateStr: 'SECONDARY',
},
]
We need to modify the replica set config like this:
const config = rs.config();
config.members[1].hidden = true;
config.members[1].priority = 0;
rs.reconfig(config)
This will set the members in the position 1 of the array (mongodb2) to the be a hidden replica set member.
In Conclusion
Production environment are much more sensitivity than localhost and staging.
You need to design your process to avoid affecting production workflow.
A hidden member is perfect for backups, running heavy queries in your BI and doing database maintenance like building a new index for a big collection.
References
https://www.mongodb.com/docs/manual/core/replica-set-hidden-member/
Woovi
Woovi is a Startup that enables shoppers to pay as they like. To make this possible, Woovi provides instant payment solutions for merchants to accept orders.
If you want to work with us, we are hiring!
Top comments (0)