Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set permernent dbpath for mongodb

Tags:

mongodb

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?

like image 355
angry kiwi Avatar asked Jan 06 '13 09:01

angry kiwi


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

like image 151
Sammaye Avatar answered Oct 22 '22 15:10

Sammaye


Just add mongod --dbpath /home/user/mongodb to your startup applications ;)

like image 42
rishy Avatar answered Oct 22 '22 14:10

rishy


sudo mongod --port portnumber --dbpath /path to your folder

By default it is set to sudo mongod --port 27017 --dbpath /var/lib/mongodb

like image 1
aaditya Avatar answered Oct 22 '22 14:10

aaditya