7

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?

7
  • Not looking into videos... the standard mongodb startup script read their configuration from a file under /etc where you can clearly configure the dbpath. What is the problem here? Apart from that: the link is not working
    – user2665694
    Jan 6, 2013 at 10:02
  • Why was this tagged with node.js? There is zero relation with node.js in your question.
    – user2665694
    Jan 6, 2013 at 10:04
  • What OS you are using? If it's *nix then you can configure dbpath and other mongodb options by editing /etc/mongodb.conf file. Jan 6, 2013 at 10:12
  • @leonid I'm using mac OS. there's no mongodb.conf in the downloaded folder for mac OS
    – angry kiwi
    Jan 6, 2013 at 10:40
  • @CRUSADER you mean the mac os system etc folder? Because there's no etc in mongo download package for mac os
    – angry kiwi
    Jan 6, 2013 at 10:42

3 Answers 3

3

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

3

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

0
1

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

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

2
  • how do you do this for setting mongo service? Can you set a path for service mongo start command?
    – rom
    May 27, 2020 at 6:12
  • 1
    You can do this in config file
    – aaditya
    May 27, 2020 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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