Reputation: 50568
I'd like to use a relative path for mongodb, so that each user has a separate data directory when running mongo.
I've tried setting
dbpath = ~/mongodb_data
in my config file, but for some reason that doesn't seem to work - I'm getting:
ERROR: dbpath (~/mongodb_data) does not exist.
At first I thought it might be a permissions error, but I'm running mongod under a user that has rw to ~/mongodb_data.
Is what I'm trying to do feasible, and, if so, how do I get to doing it?
Upvotes: 5
Views: 3117
Reputation: 3782
As of MongoDB 6.x it is possible to use relative path as data and log directory (not with tilde). For the below configuration (as an example), if the server is started from bin directory, it uses the data directory and the logs in the mentioned log file.
This is useful in cases of automated installation of MongoDB from tar.gz file, where the installation directory is not known in advance and var directory may not be accessible. The only alternative to the below is to modify the config YAML post installation to include the path to the data directory and log file (I have used the below only as an example, data and log should be outside of installation directory but could be relative to it).
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: ../log/mongod.log
# Where and how to store data.
storage:
dbPath: ../data
Upvotes: 1
Reputation: 1947
Hello blueberryfields,
I was able to do that just like that on my windows machine:
mongod --dbpath ..\..\data\db
You can use a symbolic link as well.
But as already mentioned, a update on users start up script is the best manageable solution.
Upvotes: 5
Reputation: 1563
I would specify the full path from root rather than using the tilde. I'm not sure it can use that.
dbpath = /home/yourusername/mongodb_data
Upvotes: 1