Halo, kalau kamu merasa tulisan saya ngebantu kamu, kamu bisa ucapkan terima kasih lewat saweria .

Hello, if you find this article helpful, you can express your gratitude through saweria .



There might be cases where you need to change your MongoDB storage location, typically because the current storage is almost full. So, how do you change the MongoDB storage location safely? Can you just modify the storage location in /etc/mongod.conf?

Yes, you can change the location in /etc/mongod.conf. However, you need to make sure there are no running processes in your MongoDB.

Notes:

  1. This method will work, but it requires uncertain downtime.

  2. If you have significant data in your MongoDB instance, it’s better to add a hidden replica and then promote it as a primary .


How To

  1. Shutdown MongoDB “clean way” using

    db.shutdownServer({
      force: false
    })
    
  2. Change dbPath in /etc/mongod.conf

    
    # Where and how to store data.
    storage:
      # Old location
      # dbPath: /var/lib/mongodb
      # New location
      dbPath: /var/lib/mongodb-new
    #  engine:
    #  wiredTiger:
    
  3. Check MongoDB service status sudo service mongod status; it should be inactive

Clean Shutdown MongoDB

Clean Shutdown MongoDB

  1. Start MongoDB service sudo service mongod start

Fix this one too.