Change Standalone to WiredTiger

Note

Starting in version 4.2, MongoDB removes the deprecated MMAPv1storage engine. If upgrading to MongoDB 4.2 from a MongoDB 4.0deployment that uses MMAPv1, you must upgrade to WiredTiger.

Use this tutorial to change the storage engine of a standaloneMongoDB instance to WiredTiger.

Considerations

mongodump and mongorestore

This tutorial uses the mongodump andmongorestore utilities to export and import data.

  • Ensure that these MongoDB package components are installed andupdated on your system.
  • Make sure you have sufficient drive space available for themongodump export file and the data files of your newmongod instance running with WiredTiger.

Default Bind to Localhost

Starting with MongoDB 3.6, MongoDB binaries, mongod andmongos, bind to localhost by default.From MongoDB versions 2.6 to 3.4, only the binaries from theofficial MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives)and DEB (Debian, Ubuntu, and derivatives) packages would bind tolocalhost by default. To learn more about this change, seeLocalhost Binding Compatibility Changes.

The tutorial runs mongodump andmongorestore from the same host as themongod they are connecting to. If run remotely,mongodump and mongorestore must specifythe ip address or the associated hostname in order to connect to themongod.

MongoDB 3.0 or Greater

You must be using MongoDB version 3.0 or greater in order to use theWiredTiger storage engine. If using an earlier MongoDB version, youmust upgrade your MongoDB version before proceeding to change yourstorage engine. To upgrade your MongoDB version, refer to theappropriate version of the manual.

XFS and WiredTiger

With the WiredTiger storage engine, using XFS for data bearing nodes isrecommended on Linux. For more information, seeKernel and File Systems.

MMAPv1 Only Restrictions

Once upgraded to WiredTiger, your WiredTiger deployment is notsubject to the following MMAPv1-only restrictions:

MMAPv1 RestrictionsShort Description
Number of NamespacesFor MMAPv1, the number of namespaces is limited to the size ofthe namespace file divided by 628.
Size of Namespace FileFor MMAPv1, namespace files can be no larger than 2047 megabytes.
Database SizeThe MMAPv1 storage engine limits each database to no more than16000 data files.
Data SizeFor MMAPv1, a single mongod instance cannotmanage a data set that exceeds maximum virtual memory addressspace provided by the underlying operating system.
Number of Collections in a DatabaseFor the MMAPv1 storage engine, the maximum number of collectionsin a database is a function of the size of the namespace fileand the number of indexes of collections in the database.

Procedure

Start the mongod you wish to change to WiredTiger.

If mongod is already running, you can skip this step.

Export data using mongodump.

  1. mongodump --out=<exportDataDestination>

Specify additional options as appropriate, such as username andpassword if running with authorization enabled. Seemongodump for available options.

Create a data directory for the new mongod running with WiredTiger.

Create a data directory for the new mongod instance thatwill run with the WiredTiger storage engine. mongod must have readand write permissions for this directory.

mongod with WiredTiger will not start with data files created witha different storage engine.

Update configuration for WiredTiger.

Remove any MMAPv1 Specific Configuration Options from the mongodinstance configuration.

Start mongod with WiredTiger.

Start mongod, specifying wiredTiger as the—storageEngine and the newlycreated data directory for WiredTiger as the —dbpath.

Specify additional options as appropriate, such as—bind_ip.

Warning

Before binding to a non-localhost (e.g. publicly accessible)IP address, ensure you have secured your cluster from unauthorizedaccess. For a complete list of security recommendations, seeSecurity Checklist. At minimum, considerenabling authentication andhardening network infrastructure.

  1. mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --bind_ip localhost,<hostname(s)|ip address(es)>

You can also specify the options in a configuration file. To specify the storage engine, usethe storage.engine setting.

Upload the exported data using mongorestore.

  1. mongorestore <exportDataDestination>

Specify additional options as appropriate. Seemongorestore for available options.