5

I set dbpath in mongodb config file:

#dbpath=/var/lib/mongodb
dbpath=~/data/db

Then try start mongodb but got error:

ERROR: dbpath (~/data/db) does not exist.

Allthough I can check existance of ~/data/db easy:

# cd ~/data/db
user@server:~/data/db# pwd
/root/data/db

When I run it...

# mongod --dbpath ~/data/db

... got output:

Tue Oct 15 05:05:49.040 [initandlisten] MongoDB starting : pid=3786 port=27017 dbpath=/root/data/db 64-bit host=callzone2
Tue Oct 15 05:05:49.040 [initandlisten] db version v2.4.6
Tue Oct 15 05:05:49.040 [initandlisten] git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
Tue Oct 15 05:05:49.041 [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
Tue Oct 15 05:05:49.041 [initandlisten] allocator: tcmalloc
Tue Oct 15 05:05:49.041 [initandlisten] options: { dbpath: "/root/data/db" }
Tue Oct 15 05:05:49.044 [initandlisten] exception in initAndListen std::exception: locale::facet::_S_create_c_locale name not valid, terminating
Tue Oct 15 05:05:49.044 dbexit: 
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: going to close listening sockets...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: going to flush diaglog...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: going to close sockets...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: waiting for fs preallocator...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: lock for final commit...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: final commit...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: closing all files...
Tue Oct 15 05:05:49.044 [initandlisten] closeAllFiles() finished
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: removing fs lock...
Tue Oct 15 05:05:49.044 dbexit: really exiting now

And client shows that server not started:

# mongo
MongoDB shell version: 2.4.6
connecting to: test
Tue Oct 15 05:08:22.139 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed

When I run in this way...

# sudo service mongodb restart

... got output in mongo log file:

*********************************************************************
 ERROR: dbpath (~/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
Tue Oct 15 05:10:39.311 dbexit: 
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: going to close listening sockets...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: going to flush diaglog...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: going to close sockets...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: waiting for fs preallocator...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: lock for final commit...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: final commit...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: closing all files...
Tue Oct 15 05:10:39.311 [initandlisten] closeAllFiles() finished
Tue Oct 15 05:10:39.311 dbexit: really exiting now

So cannot change dbpath.

My ubuntu version:

# uname -a
Linux hostName 3.2.0-23-virtual #36-Ubuntu SMP Tue Apr 10 22:29:03 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

3 Answers 3

5

I solved the problem with :

sudo mongod --dbpath=/var/lib/mongodb and then mongo to access the mongodb Shell.

1

What user is MongoDB running as a service?

It is usually mongod or mongodb, not root - and in fact you should not run it as root in general. The default dbpath in Ubuntu is /var/lib/mongodb so it seems you have changed that in the config file to be ~/mongodb/db.

If you do that, the ~ will expand to be the home folder for the user that the service is running as. Hence you would need to create /home/mongodb/db or /home/mongod/db/, not /root/db, and make sure it is owned by the relevant user to use that setting.

I would recommend using a full path to eliminate the confusion. Create a folder like /data/mongodb/db or similar and make sure it has the correct ownership (see this answer for more on setting permissions appropriately).

0

In my experience mongodb is very picky about the locale, I had the same issues, try:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8

sudo service mongodb restart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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