1

What i want to do: change dbpath of mongodb from /var/lib/mongodb to /home/user/mongodb/data

im using db version v3.4.7

what i've done

mkdir -p ~/mongodb/data
sudo chown -R mongodb:mongodb  /home/user/mongodb

change /etc/mongodb.conf

storage:
  dbPath: /home/user/mongodb/data/
  journal:

sudo mongod -f /etc/mongod.conf 

this works. Also tried

sudo mongod --dbpath /home/user/mongodb/data/ 

command works fine

sudo service mongod start

command fails. checking the log file.

Permission denied: "/home/user/mongodb/data/mongod.lock", terminating

what is going on? I've tried everything i know. even tried setting chmod 777 to the lock file, and still has permission denied.

1

If you now command:

sudo chown -R mongodb:mongodb  /home/user/mongodb
sudo service mongod restart

It will work!

Problems here was that you gave command sudo mongod --dbpath /home/user/mongodb/data/ what created ROOT ownded files to that /home/user/mongodb/data/ directory and your "normal" mongodb user don't have right to overwrite those.

So, NEVER start your mongod as root OR if you do so, remember reset ownership of those data files back to mongodb.

  • I tried that! but apparently not all of the files were not owned by mongod. eventually my fix was going into /home/user/mongodb, – tritium_3 Aug 9 '17 at 21:12
  • cd /home/user/mongodb/data and doing sudo chmod mongodb:mongodb *, also did sudo chmod -R 775 /home/user/mongodb, not sure if needed – tritium_3 Aug 9 '17 at 21:38
  • make sure /home/user has permissions chmod 755 – tritium_3 Mar 15 '18 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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