Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I edited the MongoDB config file to store it's data in /home/user/data/mongod.

But data is still written to the old directory, supposedly because the permissions to the new folder are not granted - how can I give MongoDB the necessary permissions for that directory?

share|improve this question
How did you edit your configuration? Why do you suppose it's a problem with the permissions? Why do you think that Mongo uses the default directory instead of throwing an error? (This is a way of asking: have you checked the errors log file?) – Andrea Corbellini Feb 18 '13 at 12:12
up vote 15 down vote accepted

To change the location used by MongoDB to store its data, you need to:

  1. Edit /etc/mongodb.conf and change the line dbpath=/var/lib/mongodb to the path that you desire, e.g. dbpath=/home/user/data/mongodb
  2. Update the permissions of your chosen path to allow the mongodb user to write to it, e.g. chown $USER -R /home/user/data/mongodb
  3. Restart the MongoDB service by running sudo service mongodb restart

Note that if you have any data in the old location that you want to keep, you'll need to stop the MongoDB service first, manually move the files and then start the service again.

To stop the MongoDB server use sudo service mongodb stop

share|improve this answer

You need to restart the daemon for changes to take effect.

sudo service mongodb restart
share|improve this answer
Ti restart the deamon i give you too ways. The old way : "etc/init.d/mongodb restart", the new way : "sudo service mongodb restart" – Cyril ALFARO Feb 18 '13 at 22:27
I recommend editing your answer to include that information. – Eliah Kagan Feb 18 '13 at 22:31

mv the /var/lib/mongodb(the directory you saved data) to the /path and chown mondodb:mongodb /path(the directory you want to save the data)

edit the /etc/mongod.conf

service mongod restart (if cannot connect,check the /path if not contains the mongod.lock,if it exists,delete it and restart again)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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