SaaS Operations

I am developing SaaS around MongoDB for other applications to be developed on it. I have 2 questions:

  1. if a single node of MongoDB is scaled up to say 3 or 5 replica-set, then do we have to restart the first node’s MongoDB or can i simply add replica-set info to it.
  2. I want to put hooks on internal events such as one of the replica-set node went down, or, leader went down, and re-election happened (and new leader is selected etc). Is that possible? If yes, how? Reference to some examples will do.


Welcome to the community @Sandeep_Kalra!

If your single node was started as a replica set, you can update the existing replica set configuration without restarting the original instance. Drivers and applications using replica set connections will automatically discover configuration changes. See Add Members to a Replica Set.

However, it is best practice to provide a seed list of 2 or more replica set members in your driver connection strings, so typically you would want to create a base replica set first (three members). The seed list of host:port pairs provided in a connection string is used by drivers/clients for initial discovery of the current replica set configuration. Upon successful connection to a member of the seed list, clients will retrieve a canonical list of replica set members to connect to, which may be different from the original seed list. If your seed list only includes a single member of your replica set, your application would be unable to connect if that member is unavailable.

There are no built-in hooks for triggering external actions on election events, since failover is handled by internal logic.

However, you can set up alerts & monitoring using operational tooling like MongoDB Cloud Manager (cloud hosted monitoring, backup, and automation) or MongoDB Ops Manager (on-prem monitoring, backup, and automation). Both of these products include alerting and APIs which you can integrate with your operational processes.

You could also consider MongoDB Atlas for a managed global cloud data service so you can focus on developing your SaaS application.

If you are interested in exploring operational approaches for the SaaS platform you are building, I suggest contacting the MongoDB sales team. We have worked with many companies building SaaS platforms and there are operational solutions ranging from fully self-hosted to cloud managed.


Thanks a lot. It clarified a lot. I am not using enterprise software as my focus is purely on FOSS at this point. I have one follow up question here:
Let’s say in a 5 node setup, and quorum of 3 [0=leader, 1-thru-4=replica] the leader was configured with users and roles (admin). and through connection I know who is the leader. At some point the leader went down, and say replica-2 is now a new leader and HA still holds true. Will it transfer the user and roles along with user-data or do I need to recreate the users and roles again?

Hi @Sandeep_Kalra,

All data written through the current primary (including users & roles) is replicated to secondaries, with the exception of the local database which has instance-specific data like the local startup_log and collections.

User and role information is stored as documents in System Collections (admin.system.users and admin.system.roles) which are reserved for internal use.

If you are new to administering MongoDB deployments, I would strongly recommend taking some of the free online courses in the MongoDB University DBA Track. The latest session of M103 (Basic Cluster Administration) just started this week and provides a good introduction to admin concepts and tasks. All curriculum (chapters & exercises) is available when you enrol, and you have two months to complete a course after enrolment.

Note: the preferred terminology for replica set roles is primary and secondary.


This was helpful. Thanks a lot.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.