Tag Archives: mongodb

Changing MongoDB storage engine from Mmapv1 to WiredTiger

Changing the storage engine for a standalone MongoDB server from Mmapv1 to WiredTiger is relatively painless.

Here’s how I did it.

1. Backup the database

mongodump --out /srv/backup/mongodb

2. Stop monbodb service

service mongodb stop

3. Update mongodb.conf

Here’s my /etc/mongodb.conf file:

# mongod.conf

storage:
  dbPath: "/var/lib/mongo" 
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1
      statisticsLogDelaySecs: 0
      journalCompressor: snappy
      directoryForIndexes: false
    collectionConfig:
      blockCompressor: snappy
    indexConfig:
      prefixCompression: true

systemLog:
  verbosity: 1
  path: "/var/log/mongodb/mongod.log" 
  logAppend: true
  logRotate: reopen
  destination: file
  timeStampFormat: iso8601-utc

processManagement:
  fork: true
  pidFilePath: "/var/run/mongodb/mongod.pid" 

net:
  bindIp: 127.0.0.1
  port: 27017
  wireObjectCheck: false
  unixDomainSocket:
    enabled: true

4. Start monbodb service

service mongodb start

5. Restore the database from backup

mongorestore /srv/backup/mongodb

That’s it.

To check what storage engine you’re using with your MongoDB, connect to the mongodb with mongo shell and run:

> db.serverStatus().storageEngine
{ "name" : "wiredTiger" }

MongoDB warning: Failed to connect

After upgrading MongoDB from version 2.4 to 2.6, I am not able to connect to it from another machine. The firewall has been checked to ensure that port 27017 is opened for the machine that I want to connect from.

So what else could go wrong?  Well, I was impatient and turned to you know what… Google search. According to this link: https://groups.google.com/forum/#!msg/mongodb-user/yhf05AW-hK8/YqES0cVIXlUJ, the problem is due to the database is bound to only local IP.

Indeed, this was the case, and I could have found it out very easily had I run the netstat command:

# netstat -tpln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       
tcp        0      0 127.0.0.1:27017             0.0.0.0:*                   LISTEN      10122/mongod 

To fix this, modify /etc/mongod.conf to include your server’s IP. Make sure you use ‘;’ instead of ‘,’ to list IP addresses.

# Listen to local interface only. Comment out to listen on all interfaces. 
bind_ip=127.0.0.1;123.123.123.123

If you use Salt to manage your server, here is an example:

include:
  - yum.mongodb

mongodb:
  pkg.installed:
    - name: mongodb-org
  service.running:
    - name: mongod
    - enable: True
    - watch:
      - file: /etc/mongod.conf

/etc/mongod.conf:
  file.managed:
    - source: salt://mongodb/files/etc/mongod.conf