I'thou trying to run Mongo from the Command-Line: What'south incorrect? (I've IIS on localhost:80). And Apache on port 8080. Are there any issues with this?

                C:\MONGO\Project1\mongo\bin>mongo --port 27017 MongoDB shell version: 2.0.3 connecting to: 127.0.0.1:27017/test Sat Mar 10 16:sixteen:45 Error: couldn't connect to server 127.0.0.one:27017 vanquish/mong o.js:86 exception: connect failed                              

user avatar

shA.t

fifteen.9k 5 golden badges 49 silverish badges 104 statuary badges

asked Mar 10, 2012 at 15:22

user avatar

five

  • Bank check if there is something using that port. in cmd: netstat -ano | findstr 27017

    Mar 10, 2012 at xv:30

  • Hey I came across the same problem and solved it past removing .lock file from \data\db binder and everything worked fine from at that place ! :)

    Apr 23, 2013 at 10:24

  • @Muhammad Riyaz how did you remove the lock file on windows 8 im trying \information\db\mongod.lock and information technology's just asking how i want to open the file.

    Dec 15, 2013 at eight:20

  • @phil i simply deleted the .lock file :) to be condom just cut and paste this file somewhere else and check if mongodb works. If it does (i m certain information technology will) yous can dekete this .lock file

    December 15, 2013 at xi:48

11 Answers 11

I found that when I got this error it wasn't because I didn't take my default db path set up up. It was because I was trying to run mongo.exe before running mongod.exe.

answered November 10, 2012 at 19:28

user avatar

3

  • this is indeed great advice.

    Apr 22, 2013 at 0:39

  • This should be the actual reply! That change in one letter is all that is needed. When searching for the exe, cmd auto completes to mongo.exe when tab is pressed. :D

    Apr 3, 2014 at 5:56

  • Fixed either - why official docs non telling about this with bold text =)

    Apr xxx, 2015 at xx:17

user avatar

shA.t

15.9k 5 gold badges 49 silver badges 104 bronze badges

answered Mar 10, 2012 at 16:53

user avatar

iv

  • C:\information\db - at that place is the path.. I thought it would create a path in the subfolder of the projection, actually that I detect a much nicer solution.

    Mar 10, 2012 at 17:11

  • You can use a custom path, hither's mine : mongod --dbpath /Mongo/db. This starts mongo in c:\mongo and the db is in c:\mongo\db

    Mar ten, 2012 at 19:38

  • What almost when creating a web application. What about security and paths?

    Mar 11, 2012 at 9:59

  • I installed mongo in e: so I needed to create e:/data/db

    Mar 31, 2015 at 14:27

  1. As Admin, create directory:

                          mkdir c:\mongo\data\db                                          
  2. As Admin, install service:

                          .\mongod.exe --install --logpath c:\mongo\logs --logappend --bind_ip 127.0.0.1 --dbpath c:\mongo\data\db --directoryperdb                                          
  3. Start MongoDB:

                          net start MongoDB                                          
  4. Start Mongo Trounce:

                          c:\mongo\bin\mongo.exe                                          

user avatar

shA.t

15.9k 5 golden badges 49 argent badges 104 bronze badges

answered Nov 19, 2013 at 9:47

user avatar

i

  • Very useful. Thank you.For the people trying this solution, notice that the "As Admin" is very of import ;)

    Jul 18, 2017 at ten:06

Follow

  1. Create default db folder.

    c:\information\db

    and also log folder

    c:\data\log\mongo.log

    or use following commands in control-prompt

                          mkdir c:\information\log     mkdir c:\data\db                                          
  2. Create config file in bin folder of mongo (or you lot may in save your desired destination).

    Add following in text file named "mongod" and save information technology every bit
    mongod.cfg
    dbpath=c:\data\db
    logpath=c:\data\log\mongo.log

    or use following commands in command-prompt

                          echo dbpath=c:\data\db>> "mongod.cfg" echo logpath=c:\data\log\mongo.log>> "mongod.cfg"                                          
  3. At present open command-prompt (ambassador) and run the following command to starting time mongo server

                          mongod                                          
  4. Open some other command-prompt (don't close 1st prompt) and run client control:

                          mongo                                          

Hope this will aid or yous have washed this already.

user avatar

answered Jul 23, 2015 at 11:27

user avatar

2

  • +1 For betoken 4. that allows you to monitor what is actually happening if you consummate 1., 2. and iii, with mongo equally a service

    October 31, 2019 at 15:08

  • Should we blazon mongod in command prompt every fourth dimension we want to showtime mongo server?

    Jan x, 2021 at 14:02

The error occurs when trying to run mongo.exe WITHOUT having executed mongod.exe. The following batch script solved the problem:

                  @echo off cd C:\mongodb\bin\ start mongod.exe get-go mongo.exe exit                                  

user avatar

MoonKnight

22.6k 39 gilt badges 139 silverish badges 264 bronze badges

answered October 21, 2014 at 13:46

user avatar

0

If you are getting these type of errors when running mongod from command line or running mongodb server, enter image description here
so follow these steps,

  1. Create db and log directories in C: drive
    C:/data/db and C:data/log
  2. Create an empty log file in log dir named mongo.log
  3. Run mongod from control line to run the mongodb server or create a batch file on desktop which can run the mongod.exe file from your mongodb installation direction. That way you merely have to click the batch file from your desktop and mongodb will start.
  4. If y'all have 32-chip system, try using --periodical with mongod control.

user avatar

answered February 17, 2016 at 17:47

user avatar

two

  • This answer helped for me quick. "try using --journal with mongod control."

    May 31, 2017 at 20:27

  • I had previous version of mongodb 3.0 and later installation version 3.6 I had the same problem. Resolved by removing everything within c:/data/log and run mongod

    Jan 9, 2018 at nineteen:47

Create default db folder.

                c:\data\db                              

and also log folder

                c:\data\log\mongo.log                              

or employ following commands in command-prompt

                mkdir c:\information\log     mkdir c:\information\db                              

user avatar

Igor

xi.8k 4 gilt badges 54 silvery badges 72 bronze badges

answered Jul 16, 2016 at 16:25

user avatar

you lot tin use beneath command,

                mongod --dbpath=D:\domicile\mongodata                              

where D:\dwelling house\mongodata is the information storage path

user avatar

Amith

6,563 half-dozen gold badges 31 silver badges 45 bronze badges

answered Oct 27, 2013 at 6:fifty

user avatar

  1. Go to C:\Program Files\MongoDB\Server\3.four\bin using cmd and write mongod.
  2. Open some other cmd by right click and run every bit admin point to your monogodb installed directory as mentioned above and then just like write this mongo.exe
  3. Afterwards that, write db.examination.save({Field:'Hullo mongodb'}) this command will insert a field having name Field and value is Hello mongodb.
  4. After, check the record db.test.find() and printing enter you will detect the tape that you lot have recently entered.

user avatar

Zub

816 1 aureate badge 12 silverish badges 22 bronze badges

answered Nov fifteen, 2017 at thirteen:05

user avatar

1

  • I.e. you have to run mongod to commencement server and mongo to run client that will use a server.

    Nov 15, 2017 at 13:xxx

Steps to kickoff a certain local MongoDB instance and to connect to in from NodeJS app:

  1. Create mongod.cfg for a new database using the path C:\Program Files\MongoDB\Server\iv.0\mongod.cfg with the content

                        systemLog:   destination: file   path: C:\Programme Files\MongoDB\Server\four.0\log\mongod.log storage:   dbPath: C:\Plan Files\MongoDB\Server\4.0\data\db                                      
  2. Install mongoDB database past running

    mongod.exe --config "C:\Program Files\MongoDB\Server\4.0\mongod.cfg" --install

  3. Run a particular mongoDB database

    mongod.exe --config "C:\Program Files\MongoDB\Server\4.0\mongod.cfg"

  4. Run mongoDB service

                        mongo 127.0.0.one:27017/db                                      

    and !encounter mongoDB bodily connection string to coonect to the service from NodeJS app

                        MongoDB trounce version v4.0.9 connecting to: mongodb://127.0.0.1:27017/db?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("c7ed5ab4-c64e-4bb8-aad0-ab4736406c03") } MongoDB server version: 4.0.9 Server has startup warnings: ...                                      

answered April 24, 2019 at two:30

user avatar

user avatar

Poul Kruijt

64.6k 11 gold badges 135 silver badges 134 bronze badges

answered Jan xiii, 2016 at fifteen:51

user avatar

Not the reply yous're looking for? Browse other questions tagged windows mongodb or enquire your own question.