Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB not working. "ERROR: dbpath (/data/db) does not exist."

I'm getting the following error when I try to run "mongod" in the terminal. I've tried uninstalling, reinstalling, and restarting the machine. Any suggestions on how to get it working would be amazing.

ERROR:

dbpath (/data/db) does not exist.  Create this directory or give existing directory in --dbpath.  See http://dochub.mongodb.org/core/startingandstoppingmongo 

Side note: Node also stopped working on my machine around the same time that I got this error.

events.js:72         throw er; // Unhandled 'error' event               ^ Error: failed to connect to [localhost:27017] 

Any help would be much appreciated!

like image 806
user3810163 Avatar asked Jul 06 '14 18:07

user3810163


2 Answers

This should work to ensure that the directory is set up in the right place so that Mongo can find it:

sudo mkdir -p /data/db/

sudo chown `id -u` /data/db

like image 92
lpappone Avatar answered Sep 29 '22 20:09

lpappone


You need to create the directory on root /data/db or set any other path with the following command :

mongod --dbpath /srv/mongodb/ 

See the example link

like image 34
Muhammad Ali Avatar answered Sep 29 '22 18:09

Muhammad Ali