How to resolve error :dbpath (/data/db/) does not exist permanently in MongoDB

Posted on May 8, 2023

Question

I have installed mongodb in my Ubuntu 10.04.

I know that when it comes to start the mongodb server with the command "mongod",then it expects /data/db folder and it can be easily resolved by creating "/data/db/". One more way is to provide your own path using mongod --dbpath "path",when we intend to give our own custom path for db.

But while going through http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ link i found that there is a configuration file.

I made the following changes to it.

# mongodb.conf

dbpath=/EBS/Work/mongodb/data/db/

logpath=/EBS/Work/mongodb/mongodb.log

logappend=true

But still when I try to start the server with "mongod" it throws the same error i.e error :dbpath (/data/db/) does not exist . I wanted to know that how can I permanently redirect my dbpath to my own custom folder cause everytime you don't want to type the path using "mongod --dbpath path".Rather we look to make some changes in configuration file.

Answer

Assuming you have followed the instructions to install a packaged version of MongoDB, you should be starting and stopping mongod using service.

To start mongod:

 sudo service mongodb start

To stop mongod:

 sudo service mongodb stop

If you use the service command to start and stop, it should be using the configuration file: /etc/mongodb.conf.

Starting mongod from the command line

If you run mongod directly instead of using the service definition, you will also have to specify a configuration file as a command line parameter if you want one to be used:

mongod --config /etc/mongodb.conf