Perform Maintenance on the Members of a MongoDB Replica Set

45 minutes
  • 3 Learning Objectives

About this Hands-on Lab

In this lab, students are asked to perform a maintenance task on each member of a MongoDB replica set. After completing this lab, students will have hands-on experience removing members from a replica set in order to perform maintenance tasks.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Determine Secondary Replica Members

Connect to any member of the replica set using mongosh and check the replica set status.

Perform Maintenance on Each Secondary Member

Connect to each secondary member, and perform the following:

  • Stop the secondary and restart as standalone instance.
  • Run the maintenance.js script.
  • Once tasks are complete, stop standalone instance and rejoin replica set.
Perform Maintenance on Primary Member

Connect to primary member and step down as primary. Once a new primary is elected (check rs.status()), proceed with the same steps as other secondary members.

Additional Resources

You are working as a DBA and are tasked with performing maintenance on the members of a MongoDB replica set. Thankfully, you've just completed an awesome Mongo Deep Dive course on acloud.guru that showed you how to do just this.

To accomplish this, you will need to complete the following tasks on each secondary member:

  • Stop the MongoDB service and restart as a standalone instance.
  • Run maintenance script.
  • Stop the standalone instance and restart as a secondary replica set member.

With the above steps completed on all secondary members, you will perform the following on the primary member:

  • Step down as primary.
  • Stop the MongoDB service and restart as a standalone instance.
  • Run maintenance script.
  • Stop the standalone instance and restart as a secondary replica set member.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?