Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo is unable to start

Tags:

mongodb

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?

like image 978
Itzik.B Avatar asked Dec 26 '16 17:12

Itzik.B


People also ask

Why is MongoDB not opening?

We found that the reason for this error was the dbpath variable in /etc/mongodb. conf. Previously, the default value for dbpath was /data/db. The upstart job mongodb(which comes with mongodb-10gen package) invokes the mongod with –config /etc/mongodb.

How do I start MongoDB in terminal?

To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.

Why is my MongoDB not connecting?

These are some of the solutions: Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.


2 Answers

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.

like image 195
RafaelCaballero Avatar answered Nov 07 '22 09:11

RafaelCaballero


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 :)

like image 37
edam Avatar answered Nov 07 '22 08:11

edam