How do I start Mongo DB from Windows?

Viewed 542387

I have installed MongoDB on my Windows 7 (64 bit) machine. I have created the path data/db too but when I tried to start mongodb using the command 'C:\mongodb\bin\mongod.exe', it is not starting. It is showing admin web console waiting for connections on port 28017.

Help me in starting the MongoDB. And also please suggest if any GUI is available for MongoDB.

20 Answers

I did below, it works for me in windows.

open cmd prompt in Administrator mode( right click command prompt and click "run as administrator")

then run below command

net start MongoDB

Download MongoDB Community Server from the link - https://www.mongodb.com/download-center/community

The installation takes some time. Once done, follow these steps to get your server running-

  1. Go to C drive, make a folder named data and inside that create another folder named db.
  2. Now move to directory where monodb server is installed. Go to C:\Program Files\MongoDB\Server(Version)\bin. Copy this file location.
  3. To make it easier to run server in future, press windows key and type environment variables.
  4. You will see an option 'Edit the system environment variables'.
  5. On the lower right corner, you will see a button 'Environment Variables...'. Click that.
  6. Under System variables, double click on path.
  7. Click on new and paste the file location you copied earlier.
  8. Now open cmd, and type mongod.exe (It's a daemon which hosts the server.)
  9. Open another window of cmd and type mongo.exe The connection will be established and you are good to go now.

Thanks for reading. Hope it helps.

an additional thing you can do that is amazing

is that you can add "C:\Program Files\MongoDB\Server\4.0\bin" to your system environment variables , this will allow you to RUN the command "mongod" in any place in your cmd without navigating to the bin directory every time.

-- note the the path to the bin directory can be different in your case --

so to arrange things up

1- make a folder data/db in your c drive "this is the default path mongo will look for the place to store your database files , so you do not have to specify it using '--dbpath' "

2- add "C:\Program Files\MongoDB\Server\4.0\bin" to your system environment variables.

3- open CMD type 'mongod'

4- have fun

-- i saw this on a youtube channel called 'thenewboston' , which is also amazing --

For Windows users:

To add onto @CoderSpeed's answer above (CoderSpeed's answer). Create a batch file (.bat) with the commands you would usually enter on the CLI, e.g.:

cd "C:\Program Files\MongoDB\Server\4.0\bin" mongod.exe

Windows Script Host’s Run Method allows you run a program or script in invisible mode. Here is a sample Windows script code that launches a batch file named syncfiles.bat invisibly.

Let’s say we have a file named syncfiles.bat in C:\Batch Files directory. Let’s launch it in hidden mode using Windows Scripting.

Copy the following lines to Notepad.

Set WshShell = CreateObject("WScript.Shell") WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0 Set WshShell = Nothing

Note: Replace the batch file name/path accordingly in the script according to your requirement. Save the file with .VBS extension, say launch_bat.vbs Edit the .BAT file name and path accordingly, and save the file. Double-click to run the launch_bat.vbs file, which in-turn launches the batch file syncfiles.bat invisibly.

Sourced from: Run .BAT files invisibly

I have installed MongoDB in D:\Installs folder instead of default location.

Open command prompt and change directory into D:\Installs\MongoDB\Server\4.4\bin and run the following command:

mongod.exe --config=mongod.cfg

This should start the MongoDB service.

Now, Open MongoDB Compass and connect as shown below:

enter image description here

  1. Restart your cmd
  2. Type mongo OR mongod in your cmd and press enter.

That's it :)

If from all these ways if your database not working you can try this

First, install Monngodb from the official site

second, go to this path

  C:\Program Files\MongoDB\Server\4.4\bin

Third run server using mongod command

Related