Dragonfly

Question: How to restart a MongoDB cluster?

Answer

Restarting a MongoDB cluster involves restarting the mongod and mongos processes on the respective nodes. This process may slightly differ based on your deployment (replica set or sharded cluster) and whether you are using MongoDB as a service (like Atlas) or managing it yourself. Here’s a general approach for a self-managed cluster:

For a Replica Set

  1. Connect to each replica set member: You need to access each member of the replica set either via SSH or through your cloud provider's management console.
  2. Stop the mongod process:
  1. Start the mongod process:

Repeat these steps for each member of the replica set, one at a time, to ensure high availability.

For a Sharded Cluster

A sharded cluster includes mongos routers, config servers, and shard servers (each being a replica set). Restart components in the following order:

  1. Config Servers: Restart all the config servers (one at a time if there are multiple) using the same method described above for replica sets.
  2. Shard Servers: For each shard (which is a replica set), restart all members using the procedure outlined for replica sets.
  3. Mongos Routers: Finally, restart all mongos processes. If these are running as services:

Considerations

Automation Tools

For larger deployments, consider using automation tools like Ops Manager or Cloud Manager (for MongoDB Enterprise) or orchestration tools like Kubernetes or Docker Swarm for managing the lifecycle of your MongoDB instances efficiently.

Was this content helpful?

Other Common MongoDB Performance Questions (and Answers)

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost