Issue running MongoDB on mac 'Unable to lock the lock file' - mongodb

I'm having trouble running MongoDB on my mac. MongoDB is the first database I've ever played with (I'm doing a tutorial) so I'm a bit lost.
I'm getting the following error in my terminal:
Joshuas-MacBook-Pro:~ joshua$ mongod
2018-07-25T14:11:36.709+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] MongoDB starting : pid=10623 port=27017 dbpath=/data/db 64-bit host=Joshuas-MacBook-Pro.local
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] db version v4.0.0
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] git version: 3b07af3d4f471ae89e8186d33bbb1d5259597d51
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] allocator: system
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] modules: none
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] build environment:
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] distarch: x86_64
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] target_arch: x86_64
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] options: {}
2018-07-25T14:11:36.725+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-07-25T14:11:36.725+0100 I CONTROL [initandlisten] now exiting
2018-07-25T14:11:36.725+0100 I CONTROL [initandlisten] shutting down with code:100
Joshuas-MacBook-Pro:~ joshua$
Does anyone have an idea of what I can do to fix it? I haven't seen any posts with people getting the 'Unable to lock the lock file' issue.
Thank you for any help!

You have already mongod instance is running and using dbPath.
You don't need to start again.
Stop or kill all mongo instance first and then start again.
Upstart: sudo service mongodb stop
Sysvinit: sudo /etc/init.d/mongodb stop
Or on Mac OS X:
Find PID of mongod process using $ top
Kill the process by $ kill <PID> (Mongo docs for more information)

Related

GoormIDE | Can't run mongod in GoormIDE Container

For context: I am creating a website in html+ejs+mongoose which I had created locally on my pc. Since I want to see the website running on another device besides my local computer, I uploaded the files on GitHub and then cloned it into an online IDE, in this case, GoormIDE, to do that.
As the title above had said, I can't run mongod in a container even though I have enabled mongoDB in the container setup. I created a file which is mongod which runs the code mongod --nojournal so that I will not have journal files in my directory. I kept receiving this error code:
2020-12-27T05:24:49.128+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] MongoDB starting : pid=802 port=27017 dbpath=/data/db 64-bit host=goorm
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] db version v4.0.22
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] git version: 1741806fb46c161a1d42870f6e98f5100d196315
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] allocator: tcmalloc
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] modules: none
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] build environment:
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] distmod: ubuntu1804
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] distarch: x86_64
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] target_arch: x86_64
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] 1024 MB of memory available to the process out of 7771 MB total system memory
2020-12-27T05:24:49.135+0000 I CONTROL [initandlisten] options: { storage: { journal: { enabled: false } } }
2020-12-27T05:24:49.135+0000 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file., terminating
2020-12-27T05:24:49.136+0000 I REPL [initandlisten] Stepping down the ReplicationCoordinator for shutdown, waitTime: 10000ms
2020-12-27T05:24:49.136+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2020-12-27T05:24:49.136+0000 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2020-12-27T05:24:49.136+0000 I NETWORK [initandlisten] Shutting down the global connection pool
2020-12-27T05:24:49.136+0000 I - [initandlisten] Killing all operations for shutdown
2020-12-27T05:24:49.136+0000 I NETWORK [initandlisten] Shutting down the ReplicaSetMonitor
2020-12-27T05:24:49.136+0000 I CONTROL [initandlisten] Shutting down free monitoring
2020-12-27T05:24:49.136+0000 I FTDC [initandlisten] Shutting down full-time data capture
2020-12-27T05:24:49.136+0000 I STORAGE [initandlisten] Shutting down the HealthLog
2020-12-27T05:24:49.136+0000 I - [initandlisten] Dropping the scope cache for shutdown
2020-12-27T05:24:49.136+0000 I CONTROL [initandlisten] now exiting
2020-12-27T05:24:49.136+0000 I CONTROL [initandlisten] shutting down with code:100
Because of this, I can't start the website because it needs mongoDB/mongoose in order to run the server.
It seems that mongod/mongoDB doesn't have a data directory. Any ideas?
I already found the answer guys!
I just need to put -dbpath ./data/db after mongod
With that, I created a directory of data/db where I will store all the data from mongoDB.
so now I edited the file that I created named "mongod" with: mongod --nojournal -dbpath ./data/db and everything works once again. I feel pretty silly not knowing this but I hope I will never make this mistake again.

(Mac) Cannot start mongo, via "mongod" command

Just trying to get up and started using the "mongod" command...
I've already looked at the following:
Cannot start mongo db
Trouble Starting MongoDB (Mac) - Code: 100
... and many other forum posts.
This is what I got in my terminal:
#####-MacBook-Pro-2:p2w4-back_end ashesmachine$ mongod
2020-05-17T13:53:02.341-0700 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-05-17T13:53:02.345-0700 W ASIO [main] No TransportLayer configured during NetworkInterface startup
2020-05-17T13:53:02.346-0700 I CONTROL [initandlisten] MongoDB starting : pid=57712 port=27017 dbpath=/data/db 64-bit host=#####-MacBook-Pro-2.local
2020-05-17T13:53:02.346-0700 I CONTROL [initandlisten] db version v4.2.6
2020-05-17T13:53:02.346-0700 I CONTROL [initandlisten] git version: 20364840b8f1af16917e4c23c1b5f5efd8b352f8
2020-05-17T13:53:02.346-0700 I CONTROL [initandlisten] allocator: system
2020-05-17T13:53:02.346-0700 I CONTROL [initandlisten] modules: none
2020-05-17T13:53:02.346-0700 I CONTROL [initandlisten] build environment:
2020-05-17T13:53:02.346-0700 I CONTROL [initandlisten] distarch: x86_64
2020-05-17T13:53:02.346-0700 I CONTROL [initandlisten] target_arch: x86_64
2020-05-17T13:53:02.346-0700 I CONTROL [initandlisten] options: {}
2020-05-17T13:53:02.346-0700 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2020-05-17T13:53:02.347-0700 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2020-05-17T13:53:02.347-0700 I - [initandlisten] Stopping further Flow Control ticket acquisitions.
2020-05-17T13:53:02.347-0700 I CONTROL [initandlisten] now exiting
2020-05-17T13:53:02.347-0700 I CONTROL [initandlisten] shutting down with code:100
You should create the data/db directory before starting mongodb. Something like mkdir -p /data/db
This worked for me:
sudo mongod --dbpath ~/Documents/data/mongo-db

Installing and Running MongoDB - Many Errors on Mac

I'm trying to install mongoDB on my Mac. However, I'm running into a lot of issues.
I first installed mongoDB using Homebrew by running the following commands:
brew tap mongodb/brew
brew install mongodb-community#4.2
Then ran it using:
brew services start mongodb-community#4.2
Everything looks fine at this point, until I try running in the terminal:
mongod
At first I thought the issue was that I didn't create the /data/db folder, so I ran:
sudo mkdir -p /data/db
This did not work.
I then found an article stating Mac users need to run:
sudo mkdir -p /System/Volumes/Data/data/db
This worked.. then I ran:
mongod --dbpath /System/Volumes/Data/data/db
And received the following:
2020-02-09T20:36:07.667-0500 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] MongoDB starting : pid=65406 port=27017 dbpath=/System/Volumes/Data/data/db 64-bit host=user-MacBook-Pro.local
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] db version v4.2.3
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] git version: 6874650b362138df74be53d366bbefc321ea32d4
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] allocator: system
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] modules: none
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] build environment:
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] distarch: x86_64
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] target_arch: x86_64
2020-02-09T20:36:07.672-0500 I CONTROL [initandlisten] options: { storage: { dbPath: "/System/Volumes/Data/data/db" } }
2020-02-09T20:36:07.673-0500 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-02-09T20:36:07.673-0500 I CONTROL [initandlisten] now exiting
2020-02-09T20:36:07.673-0500 I CONTROL [initandlisten] shutting down with code:48
I tried running:
sudo chown -Rv user /System/Volumes/Data/data/db
mongod
Then received the following:
2020-02-09T20:36:52.247-0500 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] MongoDB starting : pid=65410 port=27017 dbpath=/data/db 64-bit host=user-MacBook-Pro.local
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] db version v4.2.3
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] git version: 6874650b362138df74be53d366bbefc321ea32d4
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] allocator: system
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] modules: none
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] build environment:
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] distarch: x86_64
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] target_arch: x86_64
2020-02-09T20:36:52.249-0500 I CONTROL [initandlisten] options: {}
2020-02-09T20:36:52.250-0500 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-02-09T20:36:52.250-0500 I CONTROL [initandlisten] now exiting
2020-02-09T20:36:52.250-0500 I CONTROL [initandlisten] shutting down with code:48
For the SocketException, I tried:
mongod --port 27018
And received:
2020-02-09T20:37:39.191-0500 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] MongoDB starting : pid=65414 port=27018 dbpath=/data/db 64-bit host=user-MacBook-Pro.local
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] db version v4.2.3
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] git version: 6874650b362138df74be53d366bbefc321ea32d4
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] allocator: system
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] modules: none
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] build environment:
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] distarch: x86_64
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] target_arch: x86_64
2020-02-09T20:37:39.195-0500 I CONTROL [initandlisten] options: { net: { port: 27018 } }
2020-02-09T20:37:39.196-0500 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2020-02-09T20:37:39.196-0500 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2020-02-09T20:37:39.196-0500 I - [initandlisten] Stopping further Flow Control ticket acquisitions.
2020-02-09T20:37:39.196-0500 I CONTROL [initandlisten] now exiting
2020-02-09T20:37:39.196-0500 I CONTROL [initandlisten] shutting down with code:100
I just can't seem to figure out what's going on, since I've just been following all the steps I've found on StackOverflow from other people with this exact issue.
After doing some more research and viewing the comments above, it appears that when installing MongoDB through homebrew you will use the following commands:
brew services start mongodb-community
Then in a new tab:
mongo
This will start mongo successfully. I'm still not 100% sure why mongod kicks back errors, but for all I know, the above works.

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

sudo service mongod start : mongod: unrecognized service

I'm testing learning locker which is based on MongoDB it's all inside a ubuntu14.04 docker https://hub.docker.com/r/hadyrashwan/learninglocker-ubuntu14.04/ . I got it to work but I can't start Mongodb automatically tried the repair command and changing the name in start service command to Mongodb or mongo but not working. but running Mongodb just make it start but I want to start it automatically not opening a terminal and leave it open so the system continues to work
root#bd1997365c3a:/# mongodb
2016-09-06T07:41:51.816+0000 I CONTROL [initandlisten] MongoDB starting : pid=197 port=27017 dbpath=/data/db 64-bit host=bd1997365c3a
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] db version v3.2.9
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] modules: none
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] build environment:
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] distmod: ubuntu1404
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] distarch: x86_64
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-09-06T07:41:51.817+0000 I CONTROL [initandlisten] options: {}
2016-09-06T07:41:51.823+0000 I - [initandlisten] Detected data files in /data/db created by the 'mmapv1' storage engine, so setting the active storage engine to 'mmapv1'.
2016-09-06T07:41:51.867+0000 I JOURNAL [initandlisten] journal dir=/data/db/journal
2016-09-06T07:41:51.867+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2016-09-06T07:41:52.027+0000 I JOURNAL [durability] Durability thread started
2016-09-06T07:41:52.027+0000 I JOURNAL [journal writer] Journal writer thread started
2016-09-06T07:41:52.101+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-09-06T07:41:52.101+0000 I CONTROL [initandlisten]
2016-09-06T07:41:52.102+0000 I CONTROL [initandlisten]
2016-09-06T07:41:52.102+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-09-06T07:41:52.102+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-09-06T07:41:52.102+0000 I CONTROL [initandlisten]
2016-09-06T07:41:52.102+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-09-06T07:41:52.102+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-09-06T07:41:52.102+0000 I CONTROL [initandlisten]
2016-09-06T07:41:52.111+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2016-09-06T07:41:52.112+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-09-06T07:41:52.112+0000 I NETWORK [initandlisten] waiting for connections on port 27017
If already you install the mongodb just uninstall based on mongodb config
Before going do all stuff first install mongodb server.
sudo apt install mongodb-server
Then continue to install what mongodb config suggest you.
Once done your mongodb configuration you can go
sudo service mongodb start
Note: Its not mongod its mongodb
I had same problem. It seems there is some mis-configuration if you install via source code.
Re-installing mongoDB using apt-get activated mongod as a service for
me.