Mukund
Mukund

Reputation: 1105

Mongod not running.. E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017

I am developing a webapp in mean.io and i was following this video tutoial

https://www.youtube.com/watch?v=AEE7DY2AYvI

I already have mongodb installed in my ubuntu system and as in tutorial installed mongoose via sudo npm install mongoose (I had to give sudo system prompted me)

And after installing it i opened up another terminal and typed mongod

See its output

mukund@mukund-ThinkPad-Edge-E431:~$ mongod
2015-07-14T12:22:48.497+0530 E NETWORK  [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2015-07-14T12:22:48.497+0530 E NETWORK  [initandlisten]   addr already in use
2015-07-14T12:22:48.498+0530 I STORAGE  [initandlisten] exception in  initAndListen: 29 Data directory /data/db not found., terminating
2015-07-14T12:22:48.498+0530 I CONTROL  [initandlisten] dbexit:  rc: 100

Then I searched for the fixes in askubuntu and stackoverflow

I typed this

mukund@mukund-ThinkPad-Edge-E431:~$ netstat -an | grep :27017
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:56348         127.0.0.1:27017         ESTABLISHED
tcp        0      0 127.0.0.1:56350         127.0.0.1:27017         ESTABLISHED
tcp        0      0 127.0.0.1:27017         127.0.0.1:56349         ESTABLISHED
tcp        0      0 127.0.0.1:27017         127.0.0.1:56351         ESTABLISHED
tcp        0      0 127.0.0.1:27017         127.0.0.1:56347         ESTABLISHED
tcp        0      0 127.0.0.1:56364         127.0.0.1:27017         ESTABLISHED
tcp        0      0 127.0.0.1:56349         127.0.0.1:27017         ESTABLISHED
tcp        0      0 127.0.0.1:56351         127.0.0.1:27017         ESTABLISHED
tcp        0      0 127.0.0.1:27017         127.0.0.1:56364         ESTABLISHED
tcp        0      0 127.0.0.1:27017         127.0.0.1:56350         ESTABLISHED
tcp        0      0 127.0.0.1:56347         127.0.0.1:27017         ESTABLISHED
tcp        0      0 127.0.0.1:27017         127.0.0.1:56348         ESTABLISHED

Then

mukund@mukund-ThinkPad-Edge-E431:~$ ps aux | grep mongod
mongodb   1067  0.5  1.2 697684 96512 ?        Ssl  10:06   0:43 /usr/bin/mongod --config /etc/mongod.conf
mukund    5358  0.0  0.0  15948  2280 pts/9    S+   12:21   0:00 grep --color=auto mongod

Then as said in the fix I killed p.No 5358 and again ran mongod

mukund@mukund-ThinkPad-Edge-E431:~$ mongod
2015-07-14T12:22:48.497+0530 E NETWORK  [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2015-07-14T12:22:48.497+0530 E NETWORK  [initandlisten]   addr already in use
2015-07-14T12:22:48.498+0530 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2015-07-14T12:22:48.498+0530 I CONTROL  [initandlisten] dbexit:  rc: 100

What is wrong here? Did installing mongoose via npm command caused the issue?

One more thing to mention is that i can still connect to mogodb database via mongo command

Some one please help

Ans at last here is what i did,

reinstalled mongodb using

sudo apt-get install mongodb

then i ran mongod gave me error saying path not set, so i set the path.

Then ran mongo and everything worked!

Upvotes: 1

Views: 4003

Answers (1)

veggiesaurus
veggiesaurus

Reputation: 651

If you use apt-get to install mongodb, it creates a service that automatically starts when your computer boots. It's also started as soon as the install completes. You can stop, start or restart it using sudo service start/stop/restart mongodb (it may be "mongod" on your system)

If you want to change how it starts up, have a look in /etc/init.d for the service config. The actual mongo config that the service uses is found in /etc/mongod.conf. If you look there, you should see a line that looks like

 dbPath: /var/lib/mongodb

This defines where the database is actually stored.

Upvotes: 2

Related Questions