Mongodb get back all the databases - mongodb

Yesterday I have upgraded my Ubuntu 14.10 to 15.04. But which lead me to stop my work. I was working on chicagoboss and mongodb. i saw error that mongodb has crashed.
By typing just mongo got following error:
$ mongo
MongoDB shell version: 2.4.10
connecting to: test
Mon May 11 11:26:32.985 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
Followed stackoverflow query and removed .lock file. Then tried to repair using
$sudo mongod --repair
Then got an error:
*********************************************************************
ERROR: dbpath (/data/db/) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
I observed that in my mongodb.conf file dbpath is /var/lib/mongodb. Which is correct where I found all my mongodb databases.So I tried to set dbpath to the same location but getting error:
$ mongod --dbpath "/var/lib/mongodb"
Mon May 11 11:33:18.607 [initandlisten] MongoDB starting : pid=4450 port=27017 dbpath=/var/lib/mongodb 64-bit host=laxmikant-alphonso
Mon May 11 11:33:18.607 [initandlisten] db version v2.4.10
Mon May 11 11:33:18.607 [initandlisten] git version: e3d78955d181e475345ebd60053a4738a4c5268a
Mon May 11 11:33:18.607 [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
Mon May 11 11:33:18.607 [initandlisten] allocator: tcmalloc
Mon May 11 11:33:18.607 [initandlisten] options: { dbpath: "/var/lib/mongodb" }
Mon May 11 11:33:18.607 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /var/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Mon May 11 11:33:18.607 dbexit:
Mon May 11 11:33:18.607 [initandlisten] shutdown: going to close listening sockets...
Mon May 11 11:33:18.607 [initandlisten] shutdown: going to flush diaglog...
Mon May 11 11:33:18.607 [initandlisten] shutdown: going to close sockets...
Mon May 11 11:33:18.607 [initandlisten] shutdown: waiting for fs preallocator...
Mon May 11 11:33:18.607 [initandlisten] shutdown: lock for final commit...
Mon May 11 11:33:18.607 [initandlisten] shutdown: final commit...
Mon May 11 11:33:18.607 [initandlisten] shutdown: closing all files...
Mon May 11 11:33:18.608 [initandlisten] closeAllFiles() finished
Mon May 11 11:33:18.608 [initandlisten] shutdown: removing fs lock...
Mon May 11 11:33:18.608 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Mon May 11 11:33:18.608 dbexit: really exiting now
How can I resolve this issue. I want all my databases back.
Also I checked that I'm getting following error for service start:
$ sudo service mongodb start
Failed to start mongodb.service: Unit mongodb.service failed to load: No such file or directory.

$ mongod --dbpath "/var/lib/mongodb"
In that case, you start mongodb as yourself. And you probably don't have R/W permission on the data directory.
$ sudo service mongodb start
Now you start mongodb as a service and it will probably change its identity from root to "mongo" or something like that. On debian-like system, the configuration for mongodb is in /etc/init/mongodb.conf or preferably in /etc/mongodb.conf. See http://packages.ubuntu.com/utopic/amd64/mongodb-server/filelist. There you can change the database path.
BTW, check the permissions for your data directory. The user "mongo"-or-whatever should have write access there:
$ ls -l /var/lib/mongodb

Related

Failing to start mongo on a remote machine that I SSH into

I'm having some trouble starting up mongo. I am using it on a remote machine that I SSH into where. The remote machine is where I do everything (nothing is done on my own machine). Should I change the bind_ip from 127.0.0.1 to the remote machine's IP address? But regardless of whether I leave the IP as it is or change it to the IP of my remote machine, I get the same error message below:
melissa#simba:~$ mongo --version
MongoDB shell version: 2.6.11
melissa#simba:~$ sudo service mongod start
mongod start/running, process 10623
melissa#simba:~$ mongo
MongoDB shell version: 2.6.11
connecting to: test
2015-09-24T19:27:55.279+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-09-24T19:27:55.280+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
My remote machine is: Ubuntu 11.10 (GNU/Linux 2.6.35.4-rscloud x86_64) where the user melissa is a sudoer.
And this is the message I get when starting mongod &
melissa#simba:~$ mongod
mongod --help for help and startup options
2015-09-24T19:40:20.706+0000 [initandlisten] MongoDB starting : pid=10656 port=27017 dbpath=/data/db 64-bit host=simba
2015-09-24T19:40:20.707+0000 [initandlisten] db version v2.6.11
2015-09-24T19:40:20.707+0000 [initandlisten] git version: d00c1735675c457f75a12d530bee85421f0c5548
2015-09-24T19:40:20.707+0000 [initandlisten] build info: Linux build4.ny.cbi.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-09-24T19:40:20.707+0000 [initandlisten] allocator: tcmalloc
2015-09-24T19:40:20.707+0000 [initandlisten] options: {}
2015-09-24T19:40:20.746+0000 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2015-09-24T19:40:20.746+0000 [initandlisten] dbexit:
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: going to close listening sockets...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: going to flush diaglog...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: going to close sockets...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: waiting for fs preallocator...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: lock for final commit...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: final commit...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: closing all files...
2015-09-24T19:40:20.746+0000 [initandlisten] closeAllFiles() finished
2015-09-24T19:40:20.747+0000 [initandlisten] shutdown: removing fs lock...
2015-09-24T19:40:20.747+0000 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
2015-09-24T19:40:20.747+0000 [initandlisten] dbexit: really exiting now
More info:
melissa#simba:~$ ps -edaf | grep mongo
melissa 10748 10555 0 19:45 pts/1 00:00:00 grep --color=auto mongo
melissa#simba:~$ service mongod status
status: Unable to connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
melissa#simba:~$ sudo service mongod status
mongod stop/waiting
melissa#simba:~$ ps -aux | grep mongo
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
melissa 10786 0.0 0.3 8148 904 pts/1 S+ 19:47 0:00 grep --color=auto mongo
melissa#simba:~$ mongod --shutdown
There doesn't seem to be a server running with dbpath: /data/db
Then I tried to change the permission based on this, but got a new error:
melissa#simba:~/meeth-app$ sudo chown -R `id -u` /data/db
[sudo] password for melissa:
melissa#simba:~/meeth-app$ mongo
MongoDB shell version: 2.6.11
connecting to: test
2015-09-25T01:57:54.966+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-09-25T01:57:54.967+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
melissa#simba:~/meeth-app$ mongod &
[1] 16467
melissa#simba:~/meeth-app$ mongod --help for help and startup options
2015-09-25T01:55:07.366+0000 [initandlisten] MongoDB starting : pid=16467 port=27017 dbpath=/data/db 64-bit host=simba
2015-09-25T01:55:07.366+0000 [initandlisten] db version v2.6.11
2015-09-25T01:55:07.366+0000 [initandlisten] git version: d00c1735675c457f75a12d530bee85421f0c5548
2015-09-25T01:55:07.366+0000 [initandlisten] build info: Linux build4.ny.cbi.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-09-25T01:55:07.366+0000 [initandlisten] allocator: tcmalloc
2015-09-25T01:55:07.366+0000 [initandlisten] options: {}
2015-09-25T01:55:07.369+0000 [initandlisten] journal dir=/data/db/journal
2015-09-25T01:55:07.369+0000 [initandlisten] recover : no journal files present, no recovery needed
2015-09-25T01:55:07.370+0000 [initandlisten]
2015-09-25T01:55:07.370+0000 [initandlisten] ERROR: Insufficient free space for journal files
2015-09-25T01:55:07.370+0000 [initandlisten] Please make at least 3379MB available in /data/db/journal or use --smallfiles
2015-09-25T01:55:07.370+0000 [initandlisten]
2015-09-25T01:55:07.370+0000 [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
2015-09-25T01:55:07.370+0000 [initandlisten] dbexit:
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: going to close listening sockets...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: going to flush diaglog...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: going to close sockets...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: waiting for fs preallocator...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: lock for final commit...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: final commit...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: closing all files...
2015-09-25T01:55:07.370+0000 [initandlisten] closeAllFiles() finished
2015-09-25T01:55:07.370+0000 [initandlisten] journalCleanup...
2015-09-25T01:55:07.370+0000 [initandlisten] removeJournalFiles
2015-09-25T01:55:07.371+0000 [initandlisten] shutdown: removing fs lock...
2015-09-25T01:55:07.371+0000 [initandlisten] dbexit: really exiting now
Permission for /data are wrong. Startup cannot write the PID file or likely the db files either. Try
sudo chmod -R mongodb /data
Here is what happened that made mongo work again. Btw, I'm on Ubuntu 11.10.
Change the owner of /data from root to mongodb: sudo chown -R mongodb /data.
Add a line to turn smallfiles on in /etc/mongod.conf: smallfiles = true
Do NOT run mongod & because it's not running from a place with the right permissions, instead do sudo service mongod start and you can open the mongo shell with mongo.
Thanks to r05c03 and oldlaptop from freenode irc #linux for their help.

ubuntu install mongodb error :Failed to connect to 127.0.0.1:27017

I use sudo mongod --repair
win#win-VirtualBox:/var/lib/mongodb$sudo mongod --repair
2014-09-02T22:57:35.759+0800 [initandlisten] MongoDB starting : pid=28790 port=27017 dbpath=/data/db 64-bit host=winsome-VirtualBox
2014-09-02T22:57:35.760+0800 [initandlisten] db version v2.6.4
2014-09-02T22:57:35.761+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-02T22:57:35.761+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-02T22:57:35.762+0800 [initandlisten] allocator: tcmalloc
2014-09-02T22:57:35.762+0800 [initandlisten] options: { repair: true }
2014-09-02T22:57:35.776+0800 [initandlisten] finished checking dbs
2014-09-02T22:57:35.776+0800 [initandlisten] dbexit:
2014-09-02T22:57:35.777+0800 [initandlisten] shutdown: going to close listening sockets...
2014-09-02T22:57:35.777+0800 [initandlisten] shutdown: going to flush diaglog...
2014-09-02T22:57:35.778+0800 [initandlisten] shutdown: going to close sockets...
2014-09-02T22:57:35.778+0800 [initandlisten] shutdown: waiting for fs preallocator...
2014-09-02T22:57:35.779+0800 [initandlisten] shutdown: closing all files...
2014-09-02T22:57:35.779+0800 [initandlisten] closeAllFiles() finished
2014-09-02T22:57:35.780+0800 [initandlisten] shutdown: removing fs lock...
2014-09-02T22:57:35.780+0800 [initandlisten] dbexit: really exiting now
win#win-VirtualBox:/var/lib/mongodb$ sudo service mongod start
mongod start/running, process 28806
But still can't connect to mongodb
win#win-VirtualBox:/var/lib/mongodb$ mongo
MongoDB shell version: 2.6.4
connecting to: test
2014-09-02T22:58:07.395+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-09-02T22:58:07.396+0800 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
Can someone tell me how to fix it ? or how to install mongodb correctly?
Thanks
When you typed in the mongod command, did you also give it a path? This is usually the issue. You don't have to bother with the conf file. simply type
mongod --dbpath="put your path to where you want it to save the working area for your database here!! without these silly quotations marks I may also add!"
example: mongod --dbpath=C:/Users/Kyle-3/Desktop/DEV/dangerzonearea/test/mongodb
That is my path and don't forget if on windows to flip the slashes forward if you copied it from the or it won't work!

Mongodb error on starting

When i start mongo db it instantly crashes and goes back to the normal command line. I am on Mac runing the MEAN stack if that helps. Below is the error:
$sudo mongod
Sun Jun 1 21:01:01.728 [initandlisten] MongoDB starting : pid=47937 port=3000 dbpath=/usr/local/var/mongodb 64-bit host=NoHax4You
Sun Jun 1 21:01:01.728 [initandlisten]
Sun Jun 1 21:01:01.729 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Sun Jun 1 21:01:01.729 [initandlisten] db version v2.4.9
Sun Jun 1 21:01:01.729 [initandlisten] git version: nogitversion
Sun Jun 1 21:01:01.729 [initandlisten] build info: Darwin minimavericks.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Sun Jun 1 21:01:01.729 [initandlisten] allocator: tcmalloc
Sun Jun 1 21:01:01.729 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log", port: 3000 }
Sun Jun 1 21:01:01.729 [initandlisten] exception in initAndListen: 10310 Unable to lock file: /usr/local/var/mongodb/mongod.lock. Is a mongod instance already running?, terminating
Sun Jun 1 21:01:01.729 dbexit:
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: going to close listening sockets...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: going to flush diaglog...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: going to close sockets...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: waiting for fs preallocator...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: lock for final commit...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: final commit...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: closing all files...
Sun Jun 1 21:01:01.729 [initandlisten] closeAllFiles() finished
Sun Jun 1 21:01:01.729 dbexit: really exiting now
Thanks,
Ewan
First of all, look for other instances of mongod running on the system using the age-old command:
ps ax | grep mongod
If you see a line like -
98555 ?? S 4:40.89 mongod --dbpath /Volumes/ComputerName/data/db
-PID- -name- -------------path------------
then there is a mongod process running already. If so kill it and then start mongod again.
To kill a process with PID = 0000, in Unix like environment use -
kill -9 0000
If your console returns something like, -bash: kill: (98555) - Operation not permitted, use
sudo !!
to repeat the command as super user. This should get you going.
PS: If you haven't stored any data in your db yet, delete /data and then create the /data/db directory again. Do a sudo mongod and it should work.
I had the same issue, and this one liner fix my issue
killall mongod
Run the above command inside your Terminal
Hope that helps!
I first opened the /data/db/mongod.lock file, found my process number there, then killed it with kill -9 <processnumber>. That worked for me.

Getting an error, "Error: couldn't connect to server 127.0.0.1 shell/mongo.js" & when trying to run mongodb on mac osx lion

I am using Mac OS X Lion and i just did a fresh install of MongoDB using macports and when i try to run mongodb for the first time i get the following error
MongoDB shell version: 2.0.5
connecting to: test
Fri Jun 1 11:20:33 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
can anybody please help with this? thanks
when i run mongod i get:
hisham-agil:~ hisham$ mongod
mongod --help for help and startup options
Fri Jun 1 11:24:47 [initandlisten] MongoDB starting : pid=53452 port=27017 dbpath=/data/db/ 64-bit host=hisham-agil.local
Fri Jun 1 11:24:47 [initandlisten] db version v2.0.5, pdfile version 4.5
Fri Jun 1 11:24:47 [initandlisten] git version: nogitversion
Fri Jun 1 11:24:47 [initandlisten] build info: Darwin gamma.local 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:48:32 PST 2012; root:xnu-1699.24.23~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Fri Jun 1 11:24:47 [initandlisten] options: {}
Fri Jun 1 11:24:47 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating
Fri Jun 1 11:24:47 dbexit:
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to close listening sockets...
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to flush diaglog...
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to close sockets...
Fri Jun 1 11:24:47 [initandlisten] shutdown: waiting for fs preallocator...
Fri Jun 1 11:24:47 [initandlisten] shutdown: lock for final commit...
Fri Jun 1 11:24:47 [initandlisten] shutdown: final commit...
Fri Jun 1 11:24:47 [initandlisten] shutdown: closing all files...
Fri Jun 1 11:24:47 [initandlisten] closeAllFiles() finished
Fri Jun 1 11:24:47 dbexit: really exiting now
You're running the mongo client without starting the server first. Try running mongod first.
You'll have to specify where the mongo "workspace" is using the --dbpath switch, such as mongod --dbpath /mongo/db. The specified folder should exist.
By default mongod will try to use the directory /data/db for the database files.
In your case that directory does not exist.
Before starting mongod you should create those directories and make sure they are writable by the same user that is running mongod process.
I deleted /data/db/mongod.lock to solve the problem.
I had the same issue on my mac. Try,
sudo chown -R id -u /data/db
Then start the daemon specifying your dbpath /data/db, as in bdares post above. This worked for me.

MongoDB Data disappeared

I just had to do an emergency reboot of my linux server. I did it gracefully, not a hard reboot. I have been gathering data through a node.js app for a month, but when the server started up again, all the data was gone!
I have a long log file: http://clintberry.com/mongod.log
I also ran a repair to see if it would help but to no avail.
New Development
It looks like I was running mongo with the command 'service mongod start' and when I try to run that command again, I get this:
**************
old lock file: /var/lib/mongo/mongod.lock. probably means unclean shutdown recommend
removing file and running --repair see: http://dochub.mongodb.org/core/repair
for more information
*************
So that means the repair I was trying was not working since I wasn't using the correct config file.
When I run repair with the correct config file it doesn't seem to run repair, just spits out this:
root#es2 [/var/log/mongo]# mongod --dbpath /var/lib/mongo/ --repair
Wed Nov 30 12:09:40 [initandlisten] MongoDB starting : pid=26916 port=27017 dbpath=/var/lib/mongo/ 64-bit
Wed Nov 30 12:09:40 [initandlisten] db version v1.8.4, pdfile version 4.5
Wed Nov 30 12:09:40 [initandlisten] git version: 81f12749a15e3d158b1b16bab6bc3faea538e166
Wed Nov 30 12:09:40 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 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_41
**************
old lock file: /var/lib/mongo/mongod.lock. probably means unclean shutdown
recommend removing file and running --repair
see: http://dochub.mongodb.org/core/repair for more information
*************
Wed Nov 30 12:09:40 [initandlisten] exception in initAndListen std::exception: old lock file, terminating
Wed Nov 30 12:09:40 dbexit:
Wed Nov 30 12:09:40 [initandlisten] shutdown: going to close listening sockets...
Wed Nov 30 12:09:40 [initandlisten] shutdown: going to flush diaglog...
Wed Nov 30 12:09:40 [initandlisten] shutdown: going to close sockets...
Wed Nov 30 12:09:40 [initandlisten] shutdown: waiting for fs preallocator...
Wed Nov 30 12:09:40 [initandlisten] shutdown: closing all files...
Wed Nov 30 12:09:40 closeAllFiles() finished
Wed Nov 30 12:09:40 dbexit: really exiting now
As mpobrien's comment suggested, the issue was that when starting mongo it was using a different dbpath (location for the data). For those that have mongo installed on CentOS, if you use the service command to start mongo,
service mongod start
then mongo will use the configuration file /etc/mongo.conf when starting, which puts your dbpath as /var/lib/mongo
but if you start mongo with the regular mongod command, it will not use that folder and will use the mongo default.
Thanks for the help.