I understand that mongo db need to be started before I can interact with it. But what I don't understand why do I set the dbpath every time? I thought we only need to configure that path once. Am I correct?
3 Answers
You can solve this two ways:
- change your dbpath to the hard coded one which will point to
/data/db/
- Or make a startup script that will actually call the MongoDB instance for you
You could make a few scripts, as I said in my last point, to do this for you, as an example:
=== rnMongo.sh ===
./mongod --dbpath
Then with a single command:
./rnMongo.sh
Or as an upstart job:
# mongodb - Mongo Starter
author "lol"
description "Starts the MongoDB servers"
start on started network-services
#expect fork
exec /home/ubuntu/mongodb/bin/mongod --auth
#echo "Mongodb is now running";
#exit 0;
#stop
stop on runlevel [016]
#pre-stop
Something along those lines
sudo mongod --port portnumber --dbpath /path to your folder
By default it is set to sudo mongod --port 27017 --dbpath /var/lib/mongodb
-
how do you do this for setting mongo service? Can you set a path for service mongo start command?– romMay 27, 2020 at 6:12
-
1
/etc/mongodb.conf
file.