MongoDB has suddently shut down with "code 100" after months of running - mongodb

I have an ubuntu server running MongoDB and it has successfully been running for over a year now without any problems. Today suddenly it crashed throwing me a code 100.
ubuntu#ip-172-26-6-171:~/project$ mongod
2021-10-21T17:14:23.214+0000 I CONTROL [initandlisten] MongoDB starting : pid=868751 port=27017 dbpath=/data/db 64-bit host=ip-172-26-6-171
2021-10-21T17:14:23.215+0000 I CONTROL [initandlisten] db version v3.6.8
2021-10-21T17:14:23.215+0000 I CONTROL [initandlisten] git version: 8e540c0b6db93ce994cc548f000900bdc740f80a
2021-10-21T17:14:23.215+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1f 31 Mar 2020
2021-10-21T17:14:23.215+0000 I CONTROL [initandlisten] allocator: tcmalloc
2021-10-21T17:14:23.215+0000 I CONTROL [initandlisten] modules: none
2021-10-21T17:14:23.215+0000 I CONTROL [initandlisten] build environment:
2021-10-21T17:14:23.215+0000 I CONTROL [initandlisten] distarch: x86_64
2021-10-21T17:14:23.215+0000 I CONTROL [initandlisten] target_arch: x86_64
2021-10-21T17:14:23.215+0000 I CONTROL [initandlisten] options: {}
2021-10-21T17:14:23.220+0000 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2021-10-21T17:14:23.220+0000 I CONTROL [initandlisten] now exiting
2021-10-21T17:14:23.220+0000 I CONTROL [initandlisten] shutting down with code:100
Why is it out of nowhere while running smoothly suddenly face this error? No changes has been made or anything. It hasn't been touched. It just stopped working out of the blue...
And has I lost the database?
How do I get it up and running again? And without data loss.
EDIT FOR SOLUTION
I made the directory /data/db and moved the database files to this destination. Why it has worked for over a year and then suddenly do this, is still unknown. But fixed with this solution.

Related

My MongoDB isnt working when I type mongod in the terminal

I type in mongod to create a new db but I get this error, any idea what's going on here?
mongod
2018-08-28T18:06:36.824+0100 I CONTROL [initandlisten] MongoDB starting : pid=41812 port=27017 dbpath=/data/db 64-bit host=Ruairidhs-MacBook-Pro.local
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] db version v3.6.3
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] allocator: system
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] modules: none
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] build environment:
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] distarch: x86_64
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] target_arch: x86_64
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] options: {}
2018-08-28T18:06:36.825+0100 I STORAGE [initandlisten] exception in initAndListen: DBPathInUse: Unable to lock the lock file: /data/db/mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /data/db directory, terminating
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] now exiting
2018-08-28T18:06:36.825+0100 I CONTROL [initandlisten] shutting down with code:100
Open a new terminal window, and execute top, according to the error, you already have an instance of mongod running, so you need to find it and terminate it.

MongoDb Exiting with Code: 100

I know that there are other questions similar to this, but they do not have the same exact log and I have tried many supposed solutions that haven't worked. This is my log:
2018-05-16T00:31:32.193-0400 I CONTROL [initandlisten] MongoDB starting : pid=16976 port=27017 dbpath=/data/db 64-bit host=Edan
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] db version v3.6.1
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] git version: 025d4f4fe61efd1fb6f0005be20cb45a004093d1
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2o 27 Mar 2018
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] allocator: system
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] modules: none
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] build environment:
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] distarch: x86_64
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] target_arch: x86_64
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] options: {}
2018-05-16T00:31:32.194-0400 I STORAGE [initandlisten] exception in initAndListen: DBPathInUse: Unable to lock the lock file: /data/db/mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /data/db directory, terminating
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] now exiting
2018-05-16T00:31:32.194-0400 I CONTROL [initandlisten] shutting down with code:100
I think that I closed my terminal window before shutting down the server, and now I can't get it to work. Any help would be greatly appreciated.
It is mentioned in the log that "Another mongod instance is already running" and you need to gracefully shut down it before starting the server again.
If it didn't work, forcefully kill the mongod process and remove the lock file.
If you are on unix environment,
Run ps -A | grep mongo
Copy the process id(s)
Run kill -9 [process id]
And then remove the mongo lock file
Run sudo rm /data/db/mongod.lock

How do I resolve this mongod error code?

I am about to start an API project and I have not used Mongodb in quite a while and do not use it everyday, so the context switching it killing me right now because I have used mongod successfully and now cannot remember how to get it up and running.
I tried by simply going to my command line and typing mongod but I get this error:
2016-12-26T11:16:13.285-0500 I CONTROL [initandlisten] MongoDB starting : pid=41005 port=27017 dbpath=/data/db 64-bit host=DCortes-MacBook-Pro-3.local
2016-12-26T11:16:13.286-0500 I CONTROL [initandlisten] db version v3.4.0
2016-12-26T11:16:13.286-0500 I CONTROL [initandlisten] git version: f4240c60f005be757399042dc12f6addbc3170c1
2016-12-26T11:16:13.286-0500 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2j 26 Sep 2016
2016-12-26T11:16:13.286-0500 I CONTROL [initandlisten] allocator: system
2016-12-26T11:16:13.286-0500 I CONTROL [initandlisten] modules: none
2016-12-26T11:16:13.286-0500 I CONTROL [initandlisten] build environment:
2016-12-26T11:16:13.286-0500 I CONTROL [initandlisten] distarch: x86_64
2016-12-26T11:16:13.286-0500 I CONTROL [initandlisten] target_arch: x86_64
2016-12-26T11:16:13.286-0500 I CONTROL [initandlisten] options: {}
2016-12-26T11:16:13.288-0500 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2016-12-26T11:16:13.288-0500 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2016-12-26T11:16:13.288-0500 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2016-12-26T11:16:13.288-0500 I CONTROL [initandlisten] now exiting
2016-12-26T11:16:13.288-0500 I CONTROL [initandlisten] shutting down with code:100
and I have not been able to identify where in my directory is the error logs. Also, I have perused through Stack Overflow for similar posts but none of them spoke to what exactly is this error I am getting and how to fix it.

MongoDB server getting disconnected

I am getting the following error while running mongod in the terminal(Ubuntu 16.04 LTS).
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] MongoDB starting: pid=4810 port=27017 dbpath=/data/db 64-bit host=Rohan
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] db version v3.2.8
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] git version:ed70e33130c977bda0024c125b56d159573dbaf0
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g-fips 1 Mar 2016
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] allocator: tcmalloc
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] modules: none
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] build environment:
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] distmod: ubuntu1604
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] distarch: x86_64
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] target_arch: x86_64
2016-08-16T13:32:14.690+0530 I CONTROL [initandlisten] options: {}
2016-08-16T13:32:14.717+0530 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-08-16T13:32:14.717+0530 I - [initandlisten] Fatal Assertion 28578
2016-08-16T13:32:14.717+0530 I - [initandlisten]
***aborting after fassert() failure
Why is this happening?
I have fixed this issue myself, by deleting the mongodb-27017.sock file . I ran the service after deleting this file, which worked fine. However, I am still not sure the root cause of the issue. The output of the command ls - lat /tmp/mongodb-27017.sock is now
srwx------ 1 mongodb nogroup 0 Apr 23 06:24 /tmp/mongodb-27017.sock

MongoDB not working in Vagrant Centos Box

I cant seem to fork off an instance of the MongoDB daemon when I am logged in to a Centos 7.1 Box. I have created the data/db folder and everytime I try to run
./bin/mongod --dbpath data/db
I get a mess of errors
2016-01-26T00:44:23.820+0000 I CONTROL [initandlisten] MongoDB starting : pid=2735 port=27017 dbpath=data/db 64-bit host=localhost.localdomain
2016-01-26T00:44:23.820+0000 I CONTROL [initandlisten] db version v3.2.1
2016-01-26T00:44:23.820+0000 I CONTROL [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2
2016-01-26T00:44:23.821+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-01-26T00:44:23.821+0000 I CONTROL [initandlisten] modules: none
2016-01-26T00:44:23.821+0000 I CONTROL [initandlisten] build environment:
2016-01-26T00:44:23.821+0000 I CONTROL [initandlisten] distarch: x86_64
2016-01-26T00:44:23.821+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-01-26T00:44:23.821+0000 I CONTROL [initandlisten] options: { storage: { dbPath: "data/db" } }
2016-01-26T00:44:23.842+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-01-26T00:44:23.853+0000 E STORAGE [initandlisten] WiredTiger (22) [1453769063:853352][2735:0x7f09f2eddcc0], connection: data/db/WiredTiger.wt: fsync: Invalid argument
2016-01-26T00:44:23.856+0000 I - [initandlisten] Fatal Assertion 28561
2016-01-26T00:44:23.856+0000 I - [initandlisten]
***aborting after fassert() failure
The strange thing is I did it earlier and it worked. What could be the problem?
It turns out that putting the downloaded mongodb database in the synced folder between the host machine and the virtual machine caused some type of permissions issue or configuration issue.
When you take it out of the synced folder - which most likely has the Vagrantfile - and put it in a folder thats not synced/shared it seems to work just fine. Thought id save someone the 5 hours I wasted :-)