Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set mongod --dbpath

Tags:

unix

mongodb

very new to mongodb and databases in general. whenever i run mongo i receive this error message: ​​​

MongoDB shell version: 2.4.9 connecting to: test Thu Jan 30 13:03:33.170 Error: couldn't connect to server 127.0.0.1:27017  at src/mongo/shell/mongo.js:145 exception: connect failed 

running mongod i see this:

Thu Jan 30 13:13:36.588 [initandlisten] MongoDB starting : pid=29408 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=Kimis-MacBook-Air-2.local Thu Jan 30 13:13:36.588 [initandlisten]  Thu Jan 30 13:13:36.588 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 Thu Jan 30 13:13:36.588 [initandlisten] db version v2.4.9 Thu Jan 30 13:13:36.588 [initandlisten] git version: nogitversion Thu Jan 30 13:13:36.588 [initandlisten] build info: Darwin minilionvm.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49 Thu Jan 30 13:13:36.588 [initandlisten] allocator: tcmalloc Thu Jan 30 13:13:36.588 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb" } Thu Jan 30 13:13:36.591 [initandlisten] journal dir=/usr/local/var/mongodb/journal Thu Jan 30 13:13:36.591 [initandlisten] recover begin Thu Jan 30 13:13:36.591 [initandlisten] recover lsn: 108155770 Thu Jan 30 13:13:36.591 [initandlisten] recover /usr/local/var/mongodb/journal/j._0 Thu Jan 30 13:13:36.591 [initandlisten] journal file version number mismatch got:4147 expected:4149. if you have just upgraded, recover with old version of mongod, terminate cleanly, then upgrade. Thu Jan 30 13:13:36.592 [initandlisten] dbexception during recovery: 13536 journal version number mismatch 16711 Thu Jan 30 13:13:36.592 [initandlisten] exception in initAndListen: 13536 journal version number mismatch 16711, terminating Thu Jan 30 13:13:36.592 dbexit:  Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close listening sockets... Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to flush diaglog... Thu Jan 30 13:13:36.592 [initandlisten] shutdown: going to close sockets... Thu Jan 30 13:13:36.592 [initandlisten] shutdown: waiting for fs preallocator... Thu Jan 30 13:13:36.592 [initandlisten] shutdown: lock for final commit... Thu Jan 30 13:13:36.592 [initandlisten] shutdown: final commit... Thu Jan 30 13:13:36.592 [initandlisten] shutdown: closing all files... Thu Jan 30 13:13:36.592 [initandlisten] closeAllFiles() finished Thu Jan 30 13:13:36.592 [initandlisten] shutdown: removing fs lock... Thu Jan 30 13:13:36.592 dbexit: really exiting now 

when i manually set my mongo dpath to mongod --dbpath /data/db (as should be the default on installation) and keep it running in terminal everything runs fine. but once i close it, everything breaks again. my question is:

  1. why is my dbpath set to /usr/local/var/mongodb?
  2. how do i fix this error so mongo works on my machine?

i'm assuming i either need to permanently set the dbpath to /data/db or reconfigure something so it works with the dbpath as /usr/local/var/mongodb

i fairly new to unix commands as well so not entirely sure how to fix this error.

thank you for any suggestions!

so, digging through the mongodb documentation i read this:

"Unless specified, mongod will look for data files in the default /data/db directory. (Windows systems use the \data\db directory.) If you installed using a package management system. Check the /etc/mongodb.conf file provided by your packages to see the configuration of the dbpath."

when i took a look at the files within /etc/ there is no mongodb.conf file... however, i do see /usr/local/etc/mongod.conf... so if i understand this correctly, i should create a file called /etc/mongodb.conf and set the dbpath to /data/db.

do i need to delete the stuff within /usr/local/ as well?

i think this has something to do with how my PATH are setup... could someone explain to me how to fix this in unix so i won't have this problem?

thanks again!

like image 274
vesperae Avatar asked Jan 30 '14 05:01

vesperae


People also ask

What is mongod dbPath?

If you want mongod to store data files at a path other than /data/db you can specify a dbPath . The dbPath must exist before you start mongod . If it does not exist, create the directory and the permissions so that mongod can read and write data to this path.

How do I create a dbPath in MongoDB?

The default location for the MongoDB data directory is c:\data\db. So you need to create this folder using the Command Prompt. Execute the following command sequence. Then you need to specify set the dbpath to the created directory in mongod.exe.


2 Answers

Have only tried this on Mac:

  • Create a data directory in the root folder of your app
  • cd into your wherever you placed your mongo directory when you installed it
  • run this command:

    mongod --dbpath ~/path/to/your/app/data

You should be good to go!

like image 156
Sacha Nacar Avatar answered Sep 30 '22 19:09

Sacha Nacar


You can set dbPath in the mongodb.conf file:

storage:     dbPath: "/path/to/your/database/data/db" 

It's a YAML-based configuration file format (since Mongodb 2.6 version), so pay attention no tabs only spaces, and space after ": "

usually this file located in the *nix systems here: /etc/mongodb.conf

So then just run

$ mongod -f /etc/mongodb.conf 

And mongod process will start...

(on the Windows something like)

> C:\MongoDB\bin\mongod.exe -f C:\MongoDB\mongod.conf 
like image 28
Andrew Avatar answered Sep 30 '22 19:09

Andrew