Amitash
Amitash

Reputation: 1029

Mongodb not starting

I installed mongodb a few days ago on my ubuntu machine and I was using it without any problems. Today I had to restart my PC. After that, mongo simply wont start. It says:

Wed Sep 12 21:41:21 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating

It was working fine just a few hours ago and now it's all screwed up on reboot. I had a lot of important data stored there and I really hope it's not all lost! I need to find that data and run mongodb on that data again. I use pymongo to interract with mongodb.

I just saw the config file and it's storing the data in /var/lib/mongod as the dpath. Now how do I start mongodb specifying this dpath?

Upvotes: 3

Views: 13769

Answers (4)

Ajitesh
Ajitesh

Reputation: 1056

One of the reason for this error can be the fact that you are starting the mongodb with user as yourself. If you execute the command with sudo, the mongodb should start without error:

sudo mongod --dbpath /path/to/mongodb/data

One can find the path to mongodb data in file such as /etc/mongod.conf

Upvotes: 0

J Rassi
J Rassi

Reputation: 851

Use the following command to start mongod:

sudo service mongodb start

This will pass your system configuration file as an argument to mongod, which (as you saw) will cause it to use the correct path.

Upvotes: 3

Martyn Jones
Martyn Jones

Reputation: 118

You can start mongodb with the following switch.

mongod --dbpath /path/to/mongodb/data

Or edit the config file.

/etc/mongod.conf

Change dbpath to your data directory.

dbpath = /path/to/mongodb/data

There's a lot more you can add and change in the config file go here for more details.

Use this command to create your directory tree.

mkdir -p data/{db}

Upvotes: 7

gefei
gefei

Reputation: 19776

you need a path to store your database. by default it is /data/db/. if it does not exist you have to create it first

Upvotes: 1

Related Questions