Error on Installing MongoDB - mongodb

After I install mongodb via homebrew, I get the following message when I type mongod:
kamflamenco ~ $ mongod
2016-08-02T15:34:39.934-0700 I CONTROL [initandlisten] MongoDB starting : pid=4167 port=27017 dbpath=/data/db 64-bit host=Kenzos-MacBook-Pro.local
2016-08-02T15:34:39.935-0700 I CONTROL [initandlisten] db version v3.2.8
2016-08-02T15:34:39.935-0700 I CONTROL [initandlisten] git version: ed70e33130c977bda0024c125b56d159573dbaf0
2016-08-02T15:34:39.935-0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2h 3 May 2016
2016-08-02T15:34:39.935-0700 I CONTROL [initandlisten] allocator: system
2016-08-02T15:34:39.935-0700 I CONTROL [initandlisten] modules: none
2016-08-02T15:34:39.935-0700 I CONTROL [initandlisten] build environment:
2016-08-02T15:34:39.935-0700 I CONTROL [initandlisten] distarch: x86_64
2016-08-02T15:34:39.935-0700 I CONTROL [initandlisten] target_arch: x86_64
2016-08-02T15:34:39.935-0700 I CONTROL [initandlisten] options: {}
2016-08-02T15:34:39.936-0700 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-08-02T15:34:39.938-0700 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-08-02T15:34:39.938-0700 I CONTROL [initandlisten] dbexit: rc: 100
I am new to this and I've tried researching on the error. However, I have no luck, including typing
sudo chmod 777
The only time mongod works is if I type sudo in front of it
sudo mongod
But I do not feel this is correct...

remove the mongod.lock file:
sudo rm /data/db/mongod.lock

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

mongod src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp no file

I've really been all over StackOverflow on this and couldn't find a solution. I have uninstalled Homebrew and Mongo via, well, brew. Nothing seems to fix it. Any help would be much appreciated.
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] MongoDB starting : pid=7684 port=27017 dbpath=/data/db 64-bit host=Matts-MacBook-Pro.local
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] db version v3.4.6
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2l 25 May 2017
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] allocator: system
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] modules: none
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] build environment:
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] distarch: x86_64
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] target_arch: x86_64
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] options: {}
2017-08-03T20:29:40.018-0400 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,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),
2017-08-03T20:29:40.019-0400 E STORAGE [initandlisten] WiredTiger error (2) [1501806580:19955][7684:0x7fffbdc783c0], file:WiredTiger.wt, connection: /data/db/WiredTiger.wt: handle-open: open: No such file or directory
2017-08-03T20:29:40.029-0400 I - [initandlisten] Assertion: 28595:2: No such file or directory src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 269
2017-08-03T20:29:40.029-0400 I STORAGE [initandlisten] exception in initAndListen: 28595 2: No such file or directory, terminating
2017-08-03T20:29:40.029-0400 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-08-03T20:29:40.029-0400 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2017-08-03T20:29:40.029-0400 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-08-03T20:29:40.029-0400 I CONTROL [initandlisten] now exiting
2017-08-03T20:29:40.029-0400 I CONTROL [initandlisten] shutting down with code:100
I also have to spent more than 4 hours to find a solution you asked. In my case, the stack trace is same as in your case.
I used MongoDB 4.2. But I need to downgrade it to MongoDB 3.4. After downgrading to 3.4 above error can be seen. Then again I updated MongoDB to 4.2. Still there was that error.
Tried many solutions on Stack Overflow but nothing solved my issue. As my final option I run below command.
mongod --dbpath /data/db --repair
But it also did not work.
There were some files on my /data/db directory.
Those are WiredTiger, WiredTiger.lock, WiredTiger.turtle, diagnostic.data, journal and mongod.lock.
Removed all the files in /data/db directory.
rm -rf /data/db/*
Run above command with sudo if you are not the root user.
Then I run mongod --dbpath /data/db --repair command again.
Then I could start MongoDB successfully by running mongod --dbpath /data/db.
Do not forget add bin/mongod to PATH in .bash_profile(If you are using Mac).

MongoDB, change db path, not working

I upgraded from debian 6 to debian 8. After that I upgraded MongoDB from ~2.5 to 3.2.9. They seemed to have changed the db path since I could not see any of my databases. I upgraded the dbpath. Stil I can't see any of my databases.
seprst#SESTOWS011:/data/db$ ls
graddays graddays.0 graddays.ns journal local local.0 local.ns mongod.lock mypdb mypdb.0 mypdb.ns
seprst#SESTOWS011:/data/db$ sudo service mongod stop
seprst#SESTOWS011:/data/db$ mongod --dbpath /data/db
2016-08-17T12:02:26.468+0200 I CONTROL [initandlisten] MongoDB starting : pid=22283 port=27017 dbpath=/data/db 64-bit host=SESTOWS011
2016-08-17T12:02:26.468+0200 I CONTROL [initandlisten] db version v3.2.9
2016-08-17T12:02:26.468+0200 I CONTROL [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
2016-08-17T12:02:26.468+0200 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] allocator: tcmalloc
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] modules: none
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] build environment:
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] distmod: debian71
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] distarch: x86_64
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] target_arch: x86_64
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] options: { storage: { dbPath: "/data/db" } }
2016-08-17T12:02:26.513+0200 I - [initandlisten] Detected data files in /data/db created by the 'mmapv1' storage engine, so setting the ac tive storage engine to 'mmapv1'.
2016-08-17T12:02:26.530+0200 I JOURNAL [initandlisten] journal dir=/data/db/journal
2016-08-17T12:02:26.545+0200 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2016-08-17T12:02:26.590+0200 I JOURNAL [initandlisten] warning couldn't write to / rename file /data/db/journal/prealloc.0: couldn't open file / data/db/journal/prealloc.0 for writing errno:9 Bad file descriptor
2016-08-17T12:02:26.590+0200 I STORAGE [initandlisten] exception in initAndListen: 13516 couldn't open file /data/db/journal/j._0 for writing er rno:9 Bad file descriptor, terminating
2016-08-17T12:02:26.590+0200 I CONTROL [initandlisten] now exiting
2016-08-17T12:02:26.590+0200 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2016-08-17T12:02:26.590+0200 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2016-08-17T12:02:26.590+0200 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2016-08-17T12:02:26.590+0200 I NETWORK [initandlisten] shutdown: going to close sockets...
2016-08-17T12:02:26.591+0200 I STORAGE [initandlisten] shutdown: waiting for fs preallocator...
2016-08-17T12:02:26.591+0200 I STORAGE [initandlisten] shutdown: final commit...
2016-08-17T12:02:26.591+0200 I STORAGE [initandlisten] shutdown: closing all files...
2016-08-17T12:02:26.591+0200 I STORAGE [initandlisten] closeAllFiles() finished
2016-08-17T12:02:26.591+0200 I CONTROL [initandlisten] dbexit: rc: 100
seprst#SESTOWS011:/data/db$ sudo service mongod start
seprst#SESTOWS011:/data/db$ mongo
MongoDB shell version: 3.2.9
connecting to: test
Server has startup warnings:
2016-08-17T12:02:40.540+0200 I CONTROL [initandlisten]
2016-08-17T12:02:40.540+0200 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-08-17T12:02:40.540+0200 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-17T12:02:40.540+0200 I CONTROL [initandlisten]
> show dbs
local 0.000GB
>
Any suggestions?
there is formatting issue with comment so posting as answer
ps -xa | grep mongod
open config file cat /etc/mongod.conf
for me it's dbPath: /var/lib/mongodb
you can check your settings.
to make changes permanent at your own risk
sudo service mongod stop
sudo ln -s /data/db/ /var/lib/mongodb
sudo chown mongodb:mongodb /data/db/
sudo service mongod start
//test if mongodb user can access new location:
sudo -u mongodb -s cd /data/db/

Mongod not starting

I cannot run mongod in my ubuntu machine. I read some blogs and stackoverflow threads suggesting to change the ownership of the /var/lib/mongodb and /var/log/mongodb folders by,
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/log/mongodb
but I still cant run mongod and getting the following error message.
vinayak#vinayak-Lenovo-G500:~$ mongod
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] MongoDB starting : pid=3211 port=27017 dbpath=/data/db 64-bit host=vinayak-Lenovo-G500
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] db version v3.2.3
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] git version: b326ba837cf6f49d65c2f85e1b70f6f31ece7937
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] allocator: tcmalloc
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] modules: none
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] build environment:
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] distmod: ubuntu1404
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] distarch: x86_64
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] target_arch: x86_64
2016-03-04T09:31:29.942+0530 I CONTROL [initandlisten] options: {}
2016-03-04T09:31:29.968+0530 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2016-03-04T09:31:29.968+0530 E NETWORK [initandlisten] addr already in use
2016-03-04T09:31:29.968+0530 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-03-04T09:31:29.968+0530 I CONTROL [initandlisten] dbexit: rc: 48
vinayak#vinayak-Lenovo-G500:~$
..and I don't think so, my mongodb is corrupted as it is fresh install and I haven't tweaked anything in it.
Please suggest any solution. Thank you.
By your stack trace Error " Address already in use for socket: 0.0.0.0:27017"
You can try running on a different port
e.g
mongod --port 12345
Write following thing in the terminal and it would definitely work(it have worked for me in macbook).
sudo killall -15 mongod