17

I'm trying to start mongo uin windows10 by type: mongo in cmd.

I am getting this error:

C:\Users\Itzik>mongo
MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017
2016-12-26T19:00:16.604+0200 W NETWORK  [main] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up.
2016-12-26T19:00:16.605+0200 E QUERY    [main] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:234:13
@(connect):1:6
exception: connect failed

C:\Users\Itzik>

I have opened port 27017 in the firewall, and restart mongo's services and it still dont work.

what could it be?

Itzik.B
  • 1,023
  • 2
  • 15
  • 35

8 Answers8

35

Have you started the server? Mongodb follows a server-client architecture. mongo is the client, but before it is started you need to start mongod, which is the server.

If you haven't, start the server in advance in a different console:

mongod --dbpath "c:\data"

replacing c:\data by any folder where you want to store your data (you need to create the folder in advance).

If mongod is not in the path look in the installation path, it should be something like C:\mongodb\bin\mongod.exe.

When the server says something like 'waiting for connections', then you can go to another console and type mongo to start the client.

RafaelCaballero
  • 1,555
  • 2
  • 17
  • 24
16

In C:\Program Files\MongoDB\ you might not have permission to create file/folder for your user. And mongo installer cannot create it because of lack of Administrative permission for your user.

So in C:\Program Files\MongoDB:

  1. Create a folder named data
  2. Create a folder named db inside the folder data
  3. Now right click on the data folder and choose properties
  4. Click security tab and select your user there
  5. Click the Full control select box
  6. Click ok, ok, ok ...
  7. important! if you don't have the path "C:\Program Files\MongoDB\Server\3.4\bin" set in environment variable, please set it.
  8. Now go to shell and type : mongod --dbpath "C:\Program Files\MongoDB\data\db"

That's it :)

edam
  • 910
  • 10
  • 29
4

First start the server. Goto your installation path. Mine was in "Program Files/Mongodb/server/bin"

You will find a "mongod.exe" application.

However, the server will look for "C:/data" folder for all the databases. So create the "C:/data" folder.

Now start the mongod.exe using command prompt.

>>mongod

After this you may start the client

>>mongo

This worked out for me.

Rahul Shenoy
  • 737
  • 6
  • 10
1
  1. Open the terminal as Administrator.

    (You can simply do this by searching cmd in start and then right click and select "Run as administrator")

  2. Go to bin directory of your MongoDB folder.

    cd C:\Program Files\MongoDB\Server\3.4\bin

  3. Type following command to start mongodb server :

    mongod --dbpath "C:\Program Files\MongoDB\Server\3.4\bin\Data"

    now, server will be waiting for connections.

  4. Open a new command prompt(again as Administrator)

  5. Go to bin directory.

    cd C:\Program Files\MongoDB\Server\3.4\bin

  6. Type following command:

    mongo

This will show you a prompt of mongodb :

  >

Thanks.

Community
  • 1
  • 1
0

if u install by brew (on osx) first run sudo mkdir /data/db start mondoDB Daemon by typing mongod (leave it open) and then run mongo by typing mongo in new terminal tab

majid
  • 1
0

I also have faced the same problem. First i have typed mongodb in my command prompt ,It displays "waiting for connection on 27017" that means it is working. Then i type mongo in another Command prompt Window then above error occurred.

I was having both .dll files in my xampp\php\ext folder. (php_mongo.dll and php_mongodb.dll) I deleted Php_mongodb.dll and also it's extension from php.ini file.

Again restart command prompt,Type mongod and then mongo Now working correctly.

Regolith
  • 2,944
  • 9
  • 33
  • 50
0

First set the path in Enviroment Variables, C:\Program Files\MongoDB\Server\3.6\bin after that use bellow command

  • C:\>mkdir data
  • C:\>cd data
  • C:\data>mkdir db
  • C:\data\db>

Then go to bin directory and select mongod.exe or use mongod. Without closing previous cmd open a new cmd and start the client using mongo Now it will work.

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
MNB
  • 1
  • 1
0

This issue is resolved by creating a data directory

Then move to the bin folder of mongodb or setting path information in environment variables

Then you can enter the following command,

mongod --dbpath 'path of the data folder including data directory name'

Eg: mongod --dbpath c:\users\codemaker\data

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81