2

I'm trying to get MongoDB installed and running on my new Windows 8 computer. However, I cannot seem to be able to connect to MongoDB when using the mongo.exe shell.

I got the following error:

MongoDB shell version: 2.4.8
connecting to: test
Sun Dec 15 14:06:39.835 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:146
exception: connect failed

How can I connect to MongoDB properly? I already have MongoDB installed, along with having the Data Directory all set up. I also created a specific directory for the MongoDB log files, and installed the MongoDB service.

  • 1
    When you installed it as a service, is it actually running? Alternatively you can just start it in the foreground by running the mongod.exe. That's usually preferred for dev setups because any error messages from the database process itself are more accessible. – Philipp Dec 15 '13 at 14:33
  • Seems that mongodb doesn't run. Go to C:\mongodb\bin or whereever mongo is at your computer and run mongod. Try to connect to mongo again by running mongo in another terminal. If it works, then the service doesn't run – Zali Dec 15 '13 at 16:06
4

In the directory that you ran mongo.exe you should also see the executable mongod.exe.

  • mongo.exe is the shell that connects to the server/daemon that allows you to issue commands and query your databases.
  • mongod.exe is the actaul mongo server/daemon.

First run mongod.exe to start the server then in a new command window run mongo.exe. The shell should now connect to the running server. For production you will want to look at setting mongod as Windows Service instead of just running in a separate command window.

0

Supporting the above answer by sudo_O

Steps to start mongo on Windows 8.

  1. create a data folder in your system(Say D:\username\Documents\data\db)
  2. Go to the bin directory of Mongo and run the below command -

    mongod.exe --dbpath D:\username\Documents\data\db
    
  3. Open a new cmd prompt window bin directory of Mongo and then start the mongo shell by using command below -

    mongo.exe
    

Hope this helps!

0

Connection between mongo shell in windows is often require well set dbpath, if dbpath is already set there is no other query to connect mongodb shell. Here I mention how to connect mongo shell to mongod server using two different command prompt and how to solve dbpath does not exist error.

  • 1
    Can you include some information from the video in the answer? If the video becomes unavailable, the answer is useless. – Alexei Mar 15 '18 at 12:02
0

If you attempt to start a mongod with a --dbpath that contains data files produced by a storage engine other than the one specified by --storageEngine, mongod will refuse to start. The -dbpath is the path parameter , which mongod server check to startup.

The -dbpath <path> should be \data\db on Windows environment.

As per you log you are trying to connect Local MongoDB Instance on Default port (that is 27017).

Let's start from the beginning, after installation of MongoDB . How to connect MongoDB with mongo shell.

Note: Make sure before starting the mongod server and mongo shell , you have created the by default path of MongoDB like \data\db in your C:\ drive.

As MongoDB Documented here mongod is the primary daemon process for the MongoDB system. It handles data requests, manages data access, and performs background management operations.

To connect to a MongoDB instance running on localhost with default port 27017:

  1. At a prompt in a terminal window (or a command prompt for Windows), go to your <mongodb installation dir>:

    cd mongodb installation dir

For example in my environment it will be

C:\Program Files\MongoDB\Server\3.6\bin>mongod

Note: By default MongoDB installation directory is C:\Program Files\MongoDB\Server\x.x\bin . In my place C:\Program Files\MongoDB\Server\3.6\bin. Here x.x indicates the version number of MongoDB.

  1. to start mongo:

if you added the <mongodb installation dir>/bin to your PATH you can run mongo

mongo 

Suppose that i want to run mongo shell , so in my place the command should be like that

C:\Program Files\MongoDB\Server\3.6\bin>mongo

After running the mongo shell , you shall find the some information like that as mention below.

C:\Program Files\MongoDB\Server\3.6\bin>mongo
MongoDB shell version v3.6.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.0
Server has startup warnings:
2018-03-16T19:57:55.861+0530 I CONTROL  [initandlisten]
2018-03-16T19:57:55.862+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-03-16T19:57:55.862+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-03-16T19:57:55.862+0530 I CONTROL  [initandlisten]
2018-03-16T19:57:55.863+0530 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2018-03-16T19:57:55.863+0530 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server.
2018-03-16T19:57:55.865+0530 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP
2018-03-16T19:57:55.865+0530 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2018-03-16T19:57:55.865+0530 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2018-03-16T19:57:55.868+0530 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2018-03-16T19:57:55.870+0530 I CONTROL  [initandlisten]
2018-03-16T19:57:55.871+0530 I CONTROL  [initandlisten] Hotfix KB2731284 or later update is not installed, will zero-out data files.
2018-03-16T19:57:55.873+0530 I CONTROL  [initandlisten]
2018-03-16T19:57:55.874+0530 I CONTROL  [initandlisten] ** WARNING: The file system cache of this machine is configured to be greater than 40% of the total memory. This can lead to increased memory pressure and poor perf
ormance.
2018-03-16T19:57:55.876+0530 I CONTROL  [initandlisten] See http://dochub.mongodb.org/core/wt-windows-system-file-cache
2018-03-16T19:57:55.877+0530 I CONTROL  [initandlisten]
>

Note: The above mongo shell warning message information is in My environment. which is based on MongoDB 3.6 version. May be in your environment this message will be different. It's vary to version of MongoDB , which comes by default from MongoDB Inc.

If you shall get look like this mongo shell > command prompt. That's means you have successfully connected with mongod server.

For your confirmation check with in mongo shell , to type command like.

>show dbs

You shall get the all databases in MongoDB.

> show dbs
admin             0.000GB
test              0.000GB

If you shall get databases information in your mongo shell prompt that means you have successfully connected with mongod server.

Note: By default MongoDB shows admin and test database. And By default mongo shell connect with test database. For example, to check in mongo shell to type the command like that

> db
test
> 

For further your ref here and here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy