DEV Community

Cover image for Why should you use a hidden replica set member
Sibelius Seraphini for Woovi

Posted on • Edited on

10 1

Why should you use a hidden replica set member

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
Enter fullscreen mode Exit fullscreen mode

Run rs.status() to see what node is a SECONDARY

rs.status()
Enter fullscreen mode Exit fullscreen mode

Example output:

members: [
    {
      _id: 0,
      name: 'mongodb1:27017',
      stateStr: 'PRIMARY',
    },
    {
      _id: 1,
      name: 'mongodb2.mongo-prd:27017',
      stateStr: 'SECONDARY',
    },
]
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more