Block storage and MongoDB

July 28, 2016 1.3k views
Block Storage MongoDB

Hello,
can someone explain or point me to some solution of how to use MongoDB and new Block Storages.
I have existing MongoDB database and I want to enable it to store data on new created and mounted Blocks. Is that even possible and how can be done?
Thanks

1 comment
  • @lukaobuljen - How will you use the new block storage for your MongoDB: scaling, migrating, replication, or backup? Note that block storage is a bit slower than your typical SSD only droplets.

1 Answer

That is possible and one method of doing this is:

First stop mongodb
sudo service mongodb stop

Move your database to block storage. (Depending on the version, your database may be in a different location. Check your MongoDB config file for dbpath option.)
sudo mv /usr/local/var/mongodb /block/storage/mongodb/

Create a symlink to the new part of the database. (Depending on the version, your database may be in a different location. Check your MongoDB config file for dbpath option. )
sudo ln -s /block/storage/mongodb/ /var/lib/mongodb

Setting permissions
sudo chown mongodb:mongodb /block/storage/mongodb/

Start MongoDB
sudo service mongodb start

This is one method of doing it, you can also edit your MongoDB config file and set the dbpath option to block storage.

Have another answer? Share your knowledge.