## Pre-Fetching Indexes to Improve Replication Throughput 

To help improve the performance of applying oplog entries, MongoDB fetches memory pages that hold affected data and indexes. This pre-fetch stage minimizes the amount of time MongoDB holds the write lock while applying oplog entries. By default, secondaries will pre-fetch all Indexes (page 481). 

Optionally, you can disable all pre-fetching or only pre-fetch the index on the _id field. See the secondaryIndexPrefetch setting for more information. 

## 9.2.6 Master Slave Replication 

Important: Replica sets (page 563) replace master - slave replication for most use cases. If possible, use replica sets rather than master-slave replication for all new production deployments. This documentation remains to support legacy deployments and for archival purposes only. 

In addition to providing all the functionality of master-slave deployments, replica sets are also more robust for pro- duction use. Master-slave replication preceded replica sets and made it possible to have a large number of non-master (i.e. slave) nodes, as well as to restrict replicated operations to only a single database; however, master-slave repli- cation provides less redundancy and does not automate failover. See Deploy Master-Slave Equivalent using Replica Sets (page 598) for a replica set configuration that is equivalent to master-slave replication. If you wish to convert an existing master-slave deployment to a replica set, see Convert a Master-Slave Deployment to a Replica Set (page 599). 

## Fundamental Operations 

## Initial Deployment 

To configure a master - slave deployment, start two mongod instances: one in master mode, and the other in slave mode. 

To start a mongod instance in master mode, invoke mongod as follows: 

mongod --master --dbpath /data/masterdb/ 

With the --master option, the mongod will create a local.oplog.$main (page 654) collection, which the “op- eration log” that queues operations that the slaves will apply to replicate operations from the master. The --dbpath is optional. 

To start a mongod instance in slave mode, invoke mongod as follows: 

mongod --slave --source <masterhostname><:<port>> --dbpath /data/slavedb/ 

Specify the hostname and port of the master instance to the --source argument. The --dbpath is optional. 

For slave instances, MongoDB stores data about the source server in the local.sources (page 654) collection. 

## Configuration Options for Master-Slave Deployments 

As an alternative to specifying the --source run-time option, can add a document to local.sources (page 654) specifying the master instance, as in the following operation in the mongo shell: 

1 use local 2 db.sources.find() 3 db.sources.insert( { host: <masterhostname> <,only: databasename> } ); 

