MongoDB increase disk on the VM

mongodb

My problem is with Mongo eating up space on the disk.

Reading a few blogs no the web – I was certain – a repair would save me time as this would free up mongo's reserved space. But attempting a repair throws this error because I am at 90% disk usage :

db.repairDatabase()
{
    "ok" : 0,
    "errmsg" : "Cannot repair database my_d_b having size: 347673198592 (bytes) because free disk space is: 42874580992 (bytes)"
}

Then I tried the next step which is compacting every collection in the database using :

db.getCollectionNames().forEach(function (collectionName) {
  print('Compacting: ' + collectionName);
  db.runCommand({ compact: collectionName });
});

This reduced my disk usage by just 1%.

Now I can easily pause my apps from writing to this mongo database. I don't want to use any replset approach etc. I want to just move it to a bigger disk and move forward. I have already mounted an extra disk which 2.5times the size. I am not finding concrete steps to move the data and change mongo configuration and then start mongo process.

My repairs and compactions may be failing because they need space to operate as per my understading. If I can move this data to new disk and point mongo to the new disk, I will be good.

This is what I want to achieve – would appreciate a little direction.

Best Answer

If you have a standalone MongoDB server and can tolerate downtime, the most direct approach would be to copy the contents of your current dbPath to a directory on the new disk:

  • Stop mongod
  • Copy the contents of your dbPath to a directory on the new disk
  • Update dbPath in your configuration file to point to this new directory
  • Finally, restart mongod