Book Image

MongoDB Administrator???s Guide

By : Cyrus Dasadia
Book Image

MongoDB Administrator???s Guide

By: Cyrus Dasadia

Overview of this book

MongoDB is a high-performance and feature-rich NoSQL database that forms the backbone of the systems that power many different organizations. Packed with many features that have become essential for many different types of software professional and incredibly easy to use, this cookbook contains more than 100 recipes to address the everyday challenges of working with MongoDB. Starting with database configuration, you will understand the indexing aspects of MongoDB. The book also includes practical recipes on how you can optimize your database query performance, perform diagnostics, and query debugging. You will also learn how to implement the core administration tasks required for high-availability and scalability, achieved through replica sets and sharding, respectively. You will also implement server security concepts such as authentication, user management, role-based access models, and TLS configuration. You will also learn how to back up and recover your database efficiently and monitor server performance. By the end of this book, you will have all the information you need—along with tips, tricks, and best practices—to implement a high-performance MongoDB solution.
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Changing priority to replica set nodes


By now, you would have noticed the priority keyword in the rs.status() output. Replica set members with higher priorities are more likely to be elected as primaries. The value of a priority can range from 0 to 1000, where 0 indicates a non-voting member. A non-voting member functions as a regular member of a replica set but cannot vote in elections nor get elected as a primary.

Getting ready

For this recipe, we need a three node replica set.

How to do it...

  1. Connect to the primary member of the replica set using the mongo shell:
mongo mongodb://192.168.200.200:27017
  1. Fetch the configuration:
conf = rs.conf()
  1. Change the priorities of all members:
conf['members'][0].priority = 5
conf['members'][1].priority = 2
conf['members'][2].priority = 2
  1. Reconfigure the replica set:
rs.reconfig(conf)
  1. Check the new configuration:
rs.conf()['members']

How it works...

Like our previous recipe, we connect to the primary node and fetch the replica set configuration object. Next, in step...