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
Open another terminal window
Start mongo shell
Resolved.
This problem could be solved by the below mentioned 4 steps
1) Remove .lock file
2) repair the mongodb
3) start the mongod server
4) start the mongo client
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
(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:
mongod process
logs during the mongo shell startup attempt?
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:
Then I tried to fix using all of above answers and didn’t worked. When I tried to run mongod it said
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
Something like:
start it
Try it again
mongo
ormongo --port 27017
This error caused because Mongo Server been closed
Simple Follow these steps
In my case:
First I open config file
Comment IP and Port like this
Then restart mongodb
Finally, it’s work 😀
A little to late with the answer but I’ve encountered the same issue
Following are the steps which helped me.
c:\MongoDB\Server\3.4\bin
“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 errorexception 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/dbthen I run the mongo again and it worked.
I face same issue after searching a lot I solve this by following :
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 :
After that open another terminal and just type ‘mongo’.
Following is output you can see :
Your issue solved 🙂
I also have the same problem then I got fixed by these two lines of code. Hope, it helps
Start monogdb service using
then from the new window or terminal start mongo client using
After exhausting lots and lots of sulotions, I did-
sudo brew services start mongodb-community
rather thansudo service mongod start
and it worked.So, first try
and then to start the mongo shell, do-
FOR MACOS
Check the status of the services:
If you have something like:
So you can just to stop and restart the service like this:
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 usingmongod
command at terminalAnd 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 toC:\data\db
.Other users have suggested to add
C:\data\db
but did not talk about executingmongod
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 andmongod.lock
Simple i moved my old database files to different folder and removed everything from
/usr/local/var/mongodb
Then restarted :
And it’s working fine now.
I was getting this error on ubuntu but you can try with the following command:
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
ubuntu:
then run
check
and then run
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:
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:
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:
or more specifically:
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 OKIf not, close console and create folder
c:\data\db
and start mongod againif 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.
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
try this one:
get into the bin folder on terminal, then write:
sudo ./mongod --dbpath <write_here_the_path_to_your_database>
, click enter. (always do same thing).then in another terminal window write:
sudo ./mongo
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".
It will work fine.
For my case:
Error
Reason
mongod
not runningmongod
, will not work for no access authoritySolution
mongod
Follow this steps in terminal
I had the same error when connecting to Mongo on AWS EC2 . This is what solved it
https://serverfault.com/a/347159/62381
Remove the bind_ip from the config file
This work me:-
In Mongo 3.2 for window, you should start Mongodb service. So, run the
Command Prompt as Administrator
then net start MongoDBFinally I got this is in a simple way..
open terminal and go to the mongodb location. In my case it is
and type the following command and press enter..
Open another terminal and start the mongodb using
Thats it.. you can use mongo
This is an old question, but, as a newbie I figured I’d add that (using Webstorm) you need to click on Mongo Explorer (tab on far right hand side of your window). From there:
-Click settings.
-Click browse button (looks like a button with “…” on it).
-Go to Program Files > MongoDB > Server > 3.4 > bin > mongo.exe (your version maybe different than 3.4)
-After that, click the green plus sign on the right. A window will open
-Enter a name in “Label” slot.
-Click apply.
You should now be connected. Entering “mongod” in the terminal isn’t enough. You have to do the above steps also.
My apologies in advance to those of you who aren’t using Webstorm! Not sure about the steps using other IDE’s.
if u install by brew (on osx)
first run
sudo mkdir /data/db
start mondoDB Daemon by typing
mongod
(leave it open) and thenrun mongo by typing
mongo
in new terminal tabSimply create a folder named “data” in C drive and inside data folder create another folder named “db”. Then execute mongod.exe 🙂
First, you have to start mongod server then after in another terminal you have to start mongo shell.
For starting, mongo server
1. If you path is Default path (data/db)
simple fired mongod in terminal
2. If your path is not data/db then you command like as
follow:
mongod –dbpath ‘here your path comes’ .
For starting mongo shell,
Simply fired mongo in another terminal
If you get this waiting for connections on port 27017, then your mongo successfully started.
Hope you can get my point
i had same problem, i have deleted E:\Mongo Data Files\db\mongod.lock file, so it started working. the problem is due to improper shutdown of server. so lock file is not clean.
@shakthydoss answer worked fine once, but after the second issue the .lock wasn’t there, I just created a blank one, and it worked fine. So check if yours ain’t there.
If you are using the command line:
“ls” will list all the files in the folder, if the mongod.lock isn’t there, then:
Finally run command.
Mongo service should be working fine.
Steps to solve this issue on Windows OS:
For Windows
Instead of
mongodb://localhost:27017/yourDatabase
Write
mongodb://yourComputerName:27017/yourDatabase
Example:
mongodb://Gabriel-Laptop:27017/shop
To find your computer/laptop name write in the search bar
View your PC name
and the name nearDevice name
is the name you are looking for.Note: I read somewhere that using
localhost
keyword in Windows OS for MongoDB is not recommended (most probably here).you must access via your cmd to your
src C: \ Program Files \ MongoDB \ Server \ 4.4 \ bin
and then you must open the task manager -> service -> (select mongoDB) -> start it, and retest via the cmd and it will be solved.Don’t even try to run the journal if you haven’t done the basics yet.
Remove the lock file:
sudo rm /var/lib/mongodb/mongod.lock
In the /etc/mongodb.conf edit the bindIp parameter with 0.0.0.0 if the machine ip-address isn’t static.