i found this error when trying to run mongodb. I install it via homebrew. Please assist
Agungs-MacBook-Pro:~ agungmahaputra$ mongod
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] MongoDB starting : pid=5189 port=27017 dbpath=/data/db 64-bit host=Agungs-MacBook-Pro.local
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] db version v3.6.0
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] git version: a57d8e71e6998a2d0afde7edc11bd23e5661c915
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] allocator: system
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] modules: none
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] build environment:
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] distarch: x86_64
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] target_arch: x86_64
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] options: {}
2017-12-26T15:31:15.911+0700 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] now exiting
2017-12-26T15:31:15.911+0700 I CONTROL [initandlisten] shutting down with code:48
Agungs-MacBook-Pro:~ agungmahaputra$
You can kill the previous mongod instance and start the new one.
To kill the previous mongod instance, first search for a list of tasks running on your machine by typing,
sudo lsof -iTCP -sTCP:LISTEN -n -P
Search for mongod COMMAND and its PID and type,
sudo kill <mongo_command_pid>
Now start your mongod instance by typing,
mongod
You can see MongoDB running successfully.
You already have a process running in the port 27017 which is used by mongodb. So either you need to stop the process in that port or try with different port number.
Try mongod --port 27018
You can change the port number of your choice.
EDIT:
You can also just stop all the running instances of mongo server using
sudo killall mongod as mentioned by #Dassi Orleando in the comments.
And run mongod
Summary other(#Tony Roczz, #Balasubramani M) answer to here:
Root Cause
error: Failed to set up listener: SocketException: Address already in use
means:
previously have run mongodb
probably use default port 27017
Solution
(most case) kill and restart mongod
kill mongod
two method:
use killall
killall mongod
kill by PID
find mongod PID
method 1: ps aux | grep mongod
output can see like this: limao 425 ... /usr/local/opt/mongodb-community/bin/mongod --config /usr/local/etc/mongod.conf
method 2: lsof -iTCP -sTCP:LISTEN -n -P
output can see like this: mongod 425 limao .. TCP 127.0.0.1:27017 (LISTEN)
kill by PID: kill -9 425
re-start mongod
most case: mongod
some special case
brew services start mongodb-community
for install community version in Mac by: brew install mongodb-community
(for some people) run with another port
run with another port: mongod --port 27018
only for those want to run multiple mongod server same time
Additional Note
which port the running mongodb is using?
lsof -iTCP -sTCP:LISTEN -n -P
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 425 limao 10u IPv4 0xab744305e75263cf 0t0 TCP 127.0.0.1:27017 (LISTEN)
can see 27017 is current running mongodb port.
how to check / make sure mongod is running
check mongod status:
ps aux | grep mongod
output can see mongod service
brew services list
if installed by brew and start by brew
if you're using mongodb version 4.*
in default settings, there should be a "db" folder "/data/db" having the necessary permission.
to check it the MongoDB service started
brew services list
if not then run
brew services start mongodb
run mongo instead of mongod
I solved it pasting the command below into the command line in order to close mongo's server.
sudo pkill -f mongod
"sudo" (Super User Do) runs the command admin permissions, so it will ask you for your user password
First, shutdown the running server using:
mongod --shutdown
Then run:
sudo mongod
After running this commands below:
sudo lsof -iTCP -sTCP:LISTEN -n -P
Search for mongod COMMAND and its PID and type,
sudo kill <mongo_command_pid>
And restarting mongod, it still fails with the same error "SocketException: Address already in use MONGODB".
Server was restarted yesterday and then this happened.
Just this single command
sudo pkill -f mongod
Make Sure the error is of the port , if using macos catalina there is a reported issue for ~/data/db which also causes this.
If your mongod process is already down, just remove the .sock file in /tmp:
My mongod is already down, so does not appears in:
lsof -iTCP -sTCP:LISTEN -n -P
The error was:
[root#ol7db19c1 ~]# mongod -f /etc/csrs_2.conf
about to fork child process, waiting until server is ready for connections.
forked process: 6721
ERROR: child process failed, exited with error number 48
To see additional information in this output, start without the "--fork" option.
In the log file (/var/mongodb/db/csrs2.log):
2020-07-05T16:03:59.354-0300 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
So, find for the socket locking:
ls -ltra /tmp|grep .sock
And just remove it (do it with caution in production environment):
rm -f mongodb-26002.sock
G-luck!
This may sound obvious but you should check if mongodb is already running.
So instead of first starting the the DB by running:
sudo mongod
Try directly running:
mongo
I've installed MongoDB and I've found some unlogical things and I hope someone will answer me:
When I execute "mongo" I get logged into shell
When I execute "mongodb" I get the following errors:
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] MongoDB starting : pid=7221 port=27017 dbpath=/data/db 64-bit host=debian
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] db version v3.2.7
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] git version:
4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] modules: none
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] build environment:
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] distmod: debian71
2016-06-23T22:58:39.303+0000 I CONTROL [initandlisten] distarch: x86_64
2016-06-23T22:58:39.303+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-06-23T22:58:39.303+0000 I CONTROL [initandlisten] options: {}
2016-06-23T22:58:39.325+0000 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2016-06-23T22:58:39.325+0000 E NETWORK [initandlisten] addr already in use
2016-06-23T22:58:39.325+0000 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-06-23T22:58:39.325+0000 I CONTROL [initandlisten] dbexit: rc: 48
What is the difference between two terminal commands: mongo as a first, and mongodb as a second?
MongoDB is great because my project is schema-less but it's always a horrible experience to configure it, create roles, authorization etc.
Thanks.
mongod is the server, to which requests to connect database are passed for example.
In above error, it shows that port address 27017 is in use. It means your mongod is already runnning. You just need to run command 'mongo' to access the Mongodb shell.
There is another possibility that some other process is running on port 27017
netstat -n | grep 27017 to check if process is running and kill -9 $(lsof -ti:27017)'
To use any database service, you have to start the database Server and same is the case with mongodb, the command mongod is used to start the MongoDB Server on your local machine or server.
In your question you have asked for the command mongodb that's not correct you need to run command mongod, 'b' is not the part of this command.
When you run the mongod, it starts your mongodb server on default
port 27017.
Then you open another terminal and use the command mongo to enter
into the mongo shell and perform your database operations.
The difference between the both commands is that mongod starts the
mongodb server and mongo allows you to enter into mongo shell to
perform further database operations.
Also, when you install mongodb, you have an option to install it as a service. Installing mongodb as a service starts the mongodb server in background when you boot your system.
I am coming from riak and redis where I never had an issue with this services starting, or to interact.
This is a pervasive problem with mongo and am rather clueless. Restarting does not help.I am new to mongo.
mongo
MongoDB shell version: 2.2.1
connecting to: test
Fri Nov 9 16:44:06 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
This is what I see in the logs.
now open)
Fri Nov 9 16:44:34 [conn47] end connection 10.29.16.208:5306 (1 connection now open)
Fri Nov 9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5307 #48 (2 connections now open)
Fri Nov 9 16:45:04 [conn48] end connection 10.29.16.208:5307 (1 connection now open)
Fri Nov 9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5308 #49 (2 connections now open)
Fri Nov 9 16:45:04 [conn49] end connection 10.29.16.208:5308 (1 connection now open)
Fri Nov 9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5316 #50 (2 connections now open)
Fri Nov 9 16:45:34 [conn50] end connection 10.29.16.208:5316 (1 connection now open)
Fri Nov 9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5317 #51 (2 connections now open)
Fri Nov 9 16:45:34 [conn51] end connection 10.29.16.208:5317 (1 connection now open)
Fri Nov 9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5320 #52 (2 connections now open)
Fri Nov 9 16:46:04 [conn52] end connection 10.29.16.208:5320 (1 connection now open)
Fri Nov 9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5321 #53 (2 connections now open)
Fri Nov 9 16:46:04 [conn53] end connection 10.29.16.208:5321 (1 conn
Normally this caused because you didn't start mongod process before you try starting mongo shell.
Start mongod server
mongod
Open another terminal window
Start mongo shell
mongo
Resolved.
This problem could be solved by the below mentioned 4 steps
1) Remove .lock file
sudo rm /var/lib/mongodb/mongod.lock
2) repair the mongodb
mongod -–repair
3) start the mongod server
sudo service mongod start
4) start the mongo client
mongo
For more details take a look at http://shakthydoss.com/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/
http://shakthydoss.com/technical/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/
This method only works if you want to repair your data files without preserving the original files
To find where you dbpath resides- vim /etc/mongodb.conf
check for option dbpath=
(I have dbpath=/var/lib/mongodb)
Default: /data/db/
Typical locations include: /srv/mongodb, /var/lib/mongodb or /opt/mongodb .
Replace the /var/lib/mongodb with your dbpath
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --dbpath /var/lib/mongodb/ --repair
sudo mongod --dbpath /var/lib/mongodb/ --journal
(Make sure that you leave you terminal running in which you have run above lines,
dont press 'Ctrl+c' or quit it.)
Type the command to start mongo now in another window.
Hope this works for you !
for those who want to repair your data files while preserving the original files
mongo recover
This error is what you would see if the mongo shell was not able to talk to the mongod server.
This could be because the address was wrong (host or IP) or that it was not running. One thing to note is the log trace provided does not cover the "Fri Nov 9 16:44:06" of your mongo timestamp.
Can you:
Provide the command line arguments (if any) used to start your
mongod process
Provide the log file activity from the mongod startup as well as
logs during the mongo shell startup attempt?
Confirm that your mongod process is being started on the same
machine as the mongo shell?
I am a windows user and I installed MongoDB in November 2018 and I didn't wanted to setup data/db directories. But after few days, when I open, got an error message:
MongoDB shell version v4.0.4
connecting to: mongodb://127.0.0.1:27017
2018-12-05T20:42:40.108+0530 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:257:13
#(connect):1:6
exception: connect failed
Then I tried to fix using all of above answers and didn't worked. When I tried to run mongod it said
MongoDB starting : pid=12220 port=27017 dbpath=C:\data\db\ 64-bit host=bla
I tried to change the db path(to program files) through file system and also using cmd but those didnot worked.
Solution that worked for me is:
Opened the Task Manager (ctrl + shift + esc) -> Services tab and there was a MongoDB row with the status stopped. Then I right clicked and clicked start and everything working perfectly :).
MAC OS
Check status
brew services list
Something like:
Name Status User Plist
mongodb stopped
start it
brew services start mongodb
Try it again
mongo or mongo --port 27017
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it.
This error caused because Mongo Server been closed
Simple Follow these steps
Open Task Manager
Go to >Services
Find MongoDB
Right click and select Start
In my case:
First I open config file
sudo vi /etc/mongodb.conf
Comment IP and Port like this
#bind_ip = 127.0.0.1
#port = 27017
Then restart mongodb
sudo service mongodb restart
sudo service mongod restart
Finally, it's work :D
finn#Finn ~ $ mongo
MongoDB shell version: 2.4.9
connecting to: test
> exit
A little to late with the answer but I've encountered the same issue
Following are the steps which helped me.
Go to C:\
Create "data" folder
In "data" create "db" folder
open terminal (CMD) -> go to EX:"c:\MongoDB\Server\3.4\bin"
type in mongod => this will start mongo server (leave it opened)
Run using a GUI, EX "robomongo"
Or
open new terminal (CMD) -> go to EX:"c:\MongoDB\Server\3.4\bin"
type in "mongo" command
Make sure that your mongo is running.
I fixed this problem by trying to repair the mongodb, there I found that the directory required for the db to run was not created. It shows this error
Type: mongod, it will show the error
exception in initAndListen: 29 Data directory /data/db not found., terminating
Error happen because dbpath /data/db/ (default config) does not exist. You need to create data folder and set permission for it.
Then I create a folder on my system by the command
sudo mkdir -p /data/db/
and
sudo chown id -u /data/db
then I run the mongo again and it worked.
I face same issue after searching a lot I solve this by following :
sudo service mongodb stop
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair --dbpath /var/lib/mongodb
sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb
sudo service mongodb start
If all the above solution does not work: go to service (start>search>services) and start mongodb service. Then, in a cmd prompt, after going to bin, type :/>mongo
To connect with mongo we have to first start 'mongod' services.
following output you can see :
$ mongod
2017-03-05T00:31:39.055+0530 I CONTROL [initandlisten] MongoDB starting : pid=1481 port=27017 dbpath=/data/db 64-bit host=Prabhu-Nandans-Mac.local
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] db version v3.4.2
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] allocator: system
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] modules: none
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] build environment:
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] distarch: x86_64
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] target_arch: x86_64
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] options: {}
2017-03-05T00:31:39.056+0530 W - [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2017-03-05T00:31:39.057+0530 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-03-05T00:31:39.057+0530 W STORAGE [initandlisten] Recovering data from the last clean checkpoint.
2017-03-05T00:31:39.057+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,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),
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten]
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten]
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten]
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-03-05T00:31:39.643+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-03-05T00:31:39.643+0530 I NETWORK [thread1] waiting for connections on port 27017
2017-03-05T00:31:40.008+0530 I FTDC [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
2017-03-05T00:32:03.832+0530 I NETWORK [thread1] connection accepted from 127.0.0.1:49806 #1 (1 connection now open)
2017-03-05T00:32:03.833+0530 I NETWORK [conn1] received client metadata from 127.0.0.1:49806 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.2" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "16.4.0" } }
2017-03-05T00:32:08.376+0530 I - [conn1] end connection 127.0.0.1:49806 (1 connection now open)
After that open another terminal and just type 'mongo'.
Following is output you can see :
$ mongo
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2
Your issue solved :)
I also have the same problem then I got fixed by these two lines of code. Hope, it helps
systemctl start mongod
systemctl enable mongod
Start monogdb service using
sudo service mongod start
then from the new window or terminal start mongo client using
mongo
After exhausting lots and lots of sulotions, I did-
sudo brew services start mongodb-community rather than
sudo service mongod start and it worked.
So, first try
sudo brew services start mongodb-community
and then to start the mongo shell, do-
mongo
FOR MACOS
Check the status of the services:
brew services
If you have something like:
Name Status
mongodb-community error
So you can just to stop and restart the service like this:
brew services stop mongodb-community
brew services start mongodb-community
This was happening with me today and I resolved it in following way.
Machine: I'm using Windows 10 machine and downloaded the latest MongoDB - Community edition.
So, the problem was, I did not have C:\data\db created.
Without creating C:\data\db, I opened CMD terminal and started the database using mongod command at terminal
C:\YourInstallationPath\bin>mongod
And when I fired mongo command then I was getting the problem.
Twist, I created the necessary folders but still was getting the problem. And this is because mongo server was already running. To fix it, I fired up mongod command again, and it automatically referenced to C:\data\db.
Other users have suggested to add C:\data\db but did not talk about executing mongod again, which exactly solved my problem.
I had same problem to connect mongodb after install using brew on macOS.
The problem was also mongod.lock but before i had mongodb 3.6 installed and database directory was /usr/local/var/mongodb and it have old files and mongod.lock
Simple i moved my old database files to different folder and removed everything from /usr/local/var/mongodb
Then restarted :
brew services restart mongodb
And it's working fine now.
I was getting this error on ubuntu but you can try with the following command:
sudo service mongod start
You can try with following command:
sudo service mongod start
in my case in windows and ubuntu, i needed to create /data/db folder in root. In ubuntu, i needed one additional option; to give permissions for directory.
windows
mkdir c:/data/db
ubuntu:
sudo mkdir -p /data/db
sudo chmod 700 /data/db
then run
sudo service mongod start
check
sudo service mongod status
and then run
mongo
Remove mongod.lock file. And run "mongod -repair". uninstall/reinstall mongod service fixed that problem for me.
Thanks.
Another solution that resolved this same error for me, though this one might only be if you are accessing mongo (locally) via a SSH connection via a virtual machine (at least that's my setup), and may be a linux specific environment variable issue:
export LC_ALL=C
Also, I have had more success running mongo as a daemon service then with sudo service start, my understanding is this uses command line arguments rather then the config file so it likely is an issue with my config file:
mongod --fork --logpath /var/log/mongodb.log --auth --port 27017 --dbpath /var/lib/mongodb/admin
Create the folder C:data/db if it doesn't already exist on your computer. Turns out MongoDB requires the existence of this folder structure 'data/db' to run. I hope this helps someone.
The cause by me was the space - run this in the console:
df -h
or more specifically:
du -hs /var/lib/mongodb/
to check he disk usage. If it's ~ 99% - just clean up some space and try again!
First, go to c:\mongodb\bin> to turn on mongoDB, if you see in console that mongo is listening in port 27017, it is OK
If not, close console and create folder c:\data\db and start mongod again
if all the solution above doesn't work out perhaps then this might be one to help. Somewhere down the line you may have made connection to your local mongodb database via vagrant boxes.
vagrant up and then ssh into your vagrant machine in which you've made connection with mongodb (vagrant ssh vagrant_box_name)
comment out the bind_ip line from /etc/mongod.conf using # (sudo nano /etc/mongod.conf )
restart your mongodb daemon service (sudo service mongod restart)
voila...
OK, this may be strange. My error happened because my log grew exponentially and clogged up server space hence mongo didn't get enough space to store anything.
so I cleared the log
> /var/log/mongod.log
When we take taskbar manager, go to Service tab. There MongoDB status shows the stopped. Right click for start. Its will connect MongoDB server version.
for checking type "db".
db
test
It will work fine.
I've just installed MongoDB (standard Ubuntu build, not the latest stable) and for some reason I can't connect:
Mon Feb 6 03:11:22 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:79
exception: connect failed
Now my machine isn't 127.x.x.1 it's for some reason x.x.x.2 (But i've changed my config to bind to that address, and also tried to bind to my public IP which provided no avail.
Config:
#mongodb.conf
# Where to store the data.
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
bind_ip = 199.21.114.XX
port = 27017
I've checked the logs and only startup info is displaying in there.
I've also checked that the deamon is running too, and it is - I even tried running it manually with a --fork.
Has anyone come across this before? Or any suggestions?
Thx
UPDATE:
After a restart - here are the logs:
** WARNING: You are running in OpenVZ. This is known to be broken!!!
Tue Feb 7 19:43:32 [initandlisten] db version v1.8.2, pdfile version 4.5
Tue Feb 7 19:43:32 [initandlisten] git version: nogitversion
Tue Feb 7 19:43:32 [initandlisten] build sys info: Linux allspice 2.6.24-28-se$
Tue Feb 7 19:43:32 [initandlisten] *** warning: spider monkey build without ut$
Tue Feb 7 19:43:32 [initandlisten] waiting for connections on port 27017
Tue Feb 7 19:43:32 [websvr] web admin interface listening on port 28017
I solved this problem by commenting out the following line in my /etc/mongod.conf file.
# Listen to local interface only. Comment out to listen on all interfaces.
#bind_ip = 127.0.0.1
You will need to follow this config change with restarting the mongod process.
sudo service mongod restart
You must specify the IP (199.21.114.XX), by running mongo 199.21.114.XX.
Otherwise, if you want it to listen on localhost as well, you should remove the bind_ip setting in your config file.
Update Check your firewall config. Since you're connecting to the external IP, it can be configured to block, even from the local box.
sudo rm /var/lib/mongodb/mongod.lock
I had the same issue just because the silly mistake.
first remove mongodb file which is fine
rm -rf /tmp/mongodb-27017.sock
where I did mistake inside the /etc/mongod.conf
# network interfaces
net:
port: 27017
#bindIp: 127.0.0.1
bindIp: privateIp
instead of
net:
port: 27017
bindIp: 10.1.2.4
for listen to all available ips
bindIp: [127.0.0.1,10.128.0.2]
restart the mongodb
sudo service mongod start
hopefully this answer help for someone
in /etc/mongod.conf
I changed,
bindIp: 127.0.0.1
to
bindIp: 0.0.0.0
which is all ports. Yeah, I know it's risky, but I am running on an internal network.
BTW commenting out #bindIp: 127.0.0.1 did NOT work for me, running under Ubuntu 18.
By default, running the mongo console command will look for mongodb on your localhost, hence the 127.0.0.1 IP which is your local loopback. Also, the default config for mongod should be available on localhost. Its better to do it this way for now to start, unless you have turned on auth. Make sure you have auth enabled or your database is running openly on your public ip.
When you want to connect to a host other than localhost or your default config, you do:
mongo <host>
following steps may help you :
open terminal and run "sudo rm /var/lib/mongodb/mongod.lock"
now run " sudo mongod --repair "
now "sudo start mongodb"
now just check the status of mongodb status "sudo status mongodb"
5 lastly just invoke command "mongo"
I bumped into this when mongod was running but not yet running "properly". I'm guessing there is probably a better way to wait for it to come up after installation, but adding a sleep 10 seems to fix it.
A slightly less cavemanly approach might be to tail -f its log file and look for the event where it tells you that it is listening on the interface you specified.
local log=/var/log/mongodb/mongod.log
sudo -u mongodb touch "$log"
service mongod start &
launcher=$!
tail -0f "$log" |
grep -q 'port: 27017'
wait "$launcher"
sleep 1
The final sleep is a bit of an act of desperation; it seems to take a jiffy after it logs the startup until it's properly up and listening.
See also Bash shell script not getting connect to MongoDB even if status is active
Another way is to add mongod option param bind_ip
mongod -–help
--bind_ip arg comma separated list of ip addresses to
listen on - localhost by default
--bind_ip_all bind to all ip addresses
mongod --fork --logpath /var/log/mongodb.log --dbpath /data/db --bind_ip 0.0.0.0
If you are using windows, run the services
then check mongoDB server is running, if not running, Start it.
mongoDB server by default run on localhost:27017.
Click localhost:27017 the create an admin user first.