Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Web Technology by (47.6k points)

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 is setup... could someone explain to me how to fix this in UNIX so I won't have this problem?

thanks again!

1 Answer

0 votes
by (106k points)

To set mongod --dbpath you need to clear the files in the journal /usr/local/var/mongodb/journal/ on your config.

Also:

sudo rm /var/lib/mongodb/mongod.lock

Just in case, even though that part looks clean. And then restart.

Related questions

0 votes
1 answer
asked Oct 18, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 15, 2020 in Web Technology by ashely (50.2k points)

Browse Categories

...