Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
33
rated 0 times [  33] [ 0]  / answers: 1 / hits: 77704  / 1 Year ago, sat, march 18, 2023, 11:44:56

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?


More From » mongodb

 Answers
2

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



  1. Edit /etc/mongod.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 mongod stop then sudo service mongod start


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 mongod stop


NOTE 2
to run and manage your mongod process, you will be using your operating system's built-in init system. Recent versions of Linux tend to use systemd (which uses the systemctl command), while older versions of Linux tend to use System V init (which uses the service command).


If you are unsure which init system your platform uses, run the following command:


ps --no-headers -o comm 1


based on the result which will be:



  • systemd - select the systemd (systemctl) tab below.
    OR

  • init - select the System V Init (service) tab below.


you will execute :


sudo systemctl start mongod

in the first case and


sudo service mongod start

if you are in the second case.


[#32632] Monday, March 20, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cheeturage

Total Points: 432
Total Questions: 111
Total Answers: 115

Location: Bahrain
Member since Tue, Mar 1, 2022
2 Years ago
;