MongoDB 3.0 introduces a new storage engine called wiredTiger which results in greatly reduced memory and disk space usage.

Since my DB is currently at ~20 million objects and using up ~70GB of RAM, this update comes in at just the right time to postpone a hardware update.

How do you migrate an existing installation of MongoDB 2.6 to 3.0 and at the same time get the benefits of wiredTiger?

The Documentation refers to options which result in startup errors which prevent MongoDB from starting up. Also, file locations don't match the ones in Ubuntu (Server 14.04 LTS).

  • Is this a single instance (not a replica set)? – Adam C Jul 30 '15 at 17:33

In default installations, the configuration file is at /etc/mongod.conf. What the MongoDB docs don't mention is that when migrating to WiredTiger we also need to update the configuration file to the new YAML format introduced in 2.6.
As far as I can tell the engine option is only available in the new configuration format.
Migrating from the old storage engine consists in creating a database dump, shutting down mongodb, changing settings and then importing the dump into the new storage engine.

  1. Create a backup. Seriously. We need a database dump which we'll then import to the new database engine:

    mongodump -d db_name /backup/path/  
  2. Stop the mongodb service

    sudo service mongod stop  
  3. Move data from the current location to somewhere else (MongoDB will not startup if the data directory contains files generated by the old storage engine).

    sudo mv /var/lib/mongodb /var/lib/mongodb_26/
  4. Upgrade MongoDB to version 3.0 (from http://docs.mongodb.org/v3.0/tutorial/install-mongodb-on-ubuntu/):

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10  
    echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list  
    sudo apt-get update  
    sudo apt-get install mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools  
  5. Convert the configuration file from old (pre 2.6) to the current YAML format. The bare minimum is:

        dbPath: "/var/lib/mongodb"  
        engine: wiredTiger  
       destination: file  
       path: "/var/log/mongodb/mongod.log"  
       logAppend: true  
        port: 27017  
        # Enable the HTTP interface (Defaults to port 28017).  
            enabled: false  

    Make sure no lines in the old format remain, or MongoDB won't start.

    The full documentation for the configurtion file is at: http://docs.mongodb.org/v3.0/reference/configuration-options/

  6. Optionally make a backup of the log:

    sudo mv /var/log/mongodb/mongod.log /var/log/mongodb/mongod_26.log
  7. Restart mongodb

    sudo service mongod start
  8. Load the backup to convert data to new storage engine

    mongorestore /backup/location

After checking that all your data is ok, you can delete the directory with the old data format

sudo rm -r /var/lib/mongodb_26/

Note that for replica sets and sharded clusters there are some aditional steps: http://docs.mongodb.org/v3.0/release-notes/3.0-upgrade/?_ga=1.86531032.1131483509.1428671022#change-replica-set-storage-engine-to-wiredtiger

| improve this answer | |

Using the old configuration file format, I had success with:

| improve this answer | |
  • That is quite interesting because at the time I wrote my post, I tried exactly that and got an error (which I don't recall). – Emanuel Ey Nov 23 '15 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.