Question

I am trying to run the command

  mongod --dbpath=data/db

When I get this error:

  mongod --dbpath=data/db
 [initandlisten] MongoDB starting : pid=10161 port=27017 dbpath=data/db 64-bit host=anr   
 [initandlisten] db version v2.4.9
 [initandlisten] git version: 52fe0d21959e32a5bdbecdc62057db386e4e029c
 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
 [initandlisten] allocator: tcmalloc
 [initandlisten] options: { dbpath: "data/db" }
 [initandlisten] exception in initAndListen: 10296 
 *********************************************************************
 ERROR: dbpath (data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
 *********************************************************************

 , terminating
 dbexit: 
[initandlisten] shutdown: going to close listening sockets...
[initandlisten] shutdown: going to flush diaglog...
[initandlisten] shutdown: going to close sockets...
[initandlisten] shutdown: waiting for fs preallocator...
[initandlisten] shutdown: lock for final commit...
[initandlisten] shutdown: final commit...
[initandlisten] shutdown: closing all files...
[initandlisten] closeAllFiles() finished
dbexit: really exiting now

This is my /data/db:

.:
total 4
drwxrwxrwx 3 root root 4096 Mar 26 11:24 db

./db:
total 81928
drwxr-xr-x 2 anr anr     4096 Mar 26 16:07 journal
-rw------- 1 anr anr 67108864 Mar 26 16:07 local.0
-rw------- 1 anr anr 16777216 Mar 26 16:07 local.ns
-rwxr-xr-x 1 anr anr        0 Mar 26 16:07 mongod.lock

./db/journal:
total 3145740
-rw------- 1 anr anr 1073741824 Mar 26 16:07 prealloc.0
-rw------- 1 anr anr 1073741824 Mar 25 17:36 prealloc.1
-rw------- 1 anr anr 1073741824 Mar 25 17:36 prealloc.2

UPDATE:

Modified my path to /data/db,this is the error:

 [initandlisten] allocator: tcmalloc
 [initandlisten] options: { dbpath: "/data/db" }
 [initandlisten] journal dir=/data/db/journal
 [initandlisten] recover : no journal files present, no recovery needed
 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for   
 socket: 0.0.0.0:27017
 [initandlisten] ERROR:   addr already in use 
 [initandlisten] now exiting
 [websvr] ERROR: listen(): bind() failed errno:98 Address already in use for socket:   
 0.0.0.0:28017
 [websvr] ERROR:   addr already in use

UPDATE2:

 mongodb  10172     1  0 16:11 ?        00:00:27 /usr/bin/mongod --config 
 /etc/mongodb.conf
 anr      10865  5108  0 17:07 pts/0    00:00:00 grep --colour=auto mongod
Was it helpful?

Solution

The--db-path command doesn't use an = sign. It's just --db-path for example:

mongod --db-path /data/db

You might consider using a config file to make things easier.

Depending on your flavor of Linux, you'll need one of these commands to run the Mongod process from a config file:

mongod --config /etc/mongodb.conf
mongod -f /etc/mongodb.conf

Note that the location of the conf file can be whereever you want, you just need to make sure the user running Mongod has the appropriate permissions to it.

The config file allows you to specify most of the options you will need to run the process, including the location of the dbpath, the log path, the port and (important) forking the process into it's own background thread. An example config file might look like this:

dbpath = /data/db
logpath = /var/logs/mongo.log
logappend = true
#bind ip = 127.0.0.1
port = 27111
fork = true
rest = true
verbose = true
#auth = true
#noauth = true

The 'auth' and 'noauth' are commented out as well as bind just to indicate that those are options you can also set in the config file for Mongod startup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top