How do I start Mongo DB from Windows? - mongodb

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.

Step 1
Download the mongodb
Step 2
Follow normal setup instructions
Step 3
Create the following folder
C:\data\db
Step 4
cd to C:\Program Files\MongoDB\Server\3.2\bin>
enter command mongod
by default, mongodb server will start at port 27017
Step 5
(optionally) download RoboMongo and follow normal setup instructions
Step 6
Start RoboMongo and create a new connection on localhost:27017
Your MongoDB is started and connected with RoboMongo (now Robo 3T) - a third party GUI tool

This worked for me
mongod --port 27017 --dbpath C:\MongoDB\data\db

Download from http://www.mongodb.org/downloads
Install .msi file in folder C:\mongodb
Create data, data\db, log directories and mongo.config file under C:\mongodb.
Add the following lines in "mongo.config" file
port=27017
dbpath=C:\mongodb\data\db\
logpath=C:\mongodb\log\mongo.log
Start server :
mongod.exe --config="C:\mongodb\mongo.config"
Connect to localhost MongoDB server via command line
mongo --port 27017
Connect to remote MongoDB server via command line with authentication.
mongo --username abcd --password abc123 --host server_ip_or_dns --port 27017
That's it !!!

Create MongoDB Service in Windows. First Open cmd with administrator
mongod --port 27017 --dbpath "a mongodb storage actual path e.g: d:\mongo_storage\data" --logpath="a log path e.g: d:\mongo_storage\log\log.txt" --install --serviceName "MongoDB"
After that
Start Service
net start MongoDB
Stop Service
net stop MongoDB

Step 1:
First download the .msi i.e is the installation file from
https://www.mongodb.org/downloads#production
Step 2:
Perform the installation using the so downloaded .msi file.Automatically it gets stored in program files.
You could perform a custom installation and change the directory.
After this you should be able to see a Mongodb folder
Step 3:
Create a new folder in this Mongodb folder with name 'data'. Create another new folder in your data directory with the name 'db'.
Step 4:
Open cmd. Go to the directory where your mongodb folder exists and go to a path like C:\MongoDB\Server\3.0\bin.
In the bin folder you should have mongodb.exe
Step 5:
Now use
mongod --port 27017 --dbpath "C:\MongoDB\data\db"

there are 2 ways start mongoDB
Install location ( ex : C:/ )
first of all : copy mongoDB install folder into C:/ location
then changed name to "mongodb" or something what u want. here is ex with "mongodb" name
1 : setup mongoDB is an windows service
1.1 : Make directory name "data" in C:/ ( so we have C:/data ),after that make directory "C:/data/db" <br>
1.2 : run in CMD ( Run as Admin) command -> "echo logpath=C:/mongodb/log/mongo.log > C:/mongodb/mongodb.cfg" <br>
1.3 : run in CMD (Run as Adin) command -> "C:/mongodb/bin/mongod.exe --config C:/mongodb/mongod.cfg --install" <br>
1.4 : run command "net start MongoDB" <br>
2: a small .BAT file to start mongoDB without install
copy and paste to notepad and save file with filetype ".bat"
here is it :
C:\mongodb\bin\mongod.exe –dbpath=C:/mongodb/data/db
PAUSE
if you getting error 1078 or 1087
lets remove all data in C:/data/db and restart mongoDB ( copy old data to new folder and back it up after restart mongoDB )
3 . GUI for mongoDB
i'm using rockmongo
have fun with it

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

I have followed the below steps...May be it will work for you
Create directory like below
C:\DATA\DB
mongod --port 27017 --dbpath "C:\data\db"
It worked for me....

It is properly written over here
If you download the .msi file then install it and if you download the zip file then extract it.
Set up the MongoDB environment.
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is \data\db. Create this folder using the following commands from a Command Prompt:
md \data\db
You can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data
If your path includes spaces, enclose the entire path in double quotes, for example:
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"
You may also specify the dbpath in a configuration file.
Start MongoDB.
To start MongoDB, run mongod.exe. For example, from the Command Prompt:
C:\mongodb\bin\mongod.exe
Connect to MongoDB.
To connect to MongoDB through the mongo.exe shell, open another Command Prompt.
C:\mongodb\bin\mongo.exe

It is showing admin web console waiting for connections on port 28017.
The above message means that mongodb has started successfully and is listening on port 28017.
You can use the mongo shell(mongo.exe) to connect to the mongoDB and perform db operations.
There are several GUI tools available for MongoDB like MongoVUE, etc.

Installing MongoDB on Windows is a bit tricky compared to other Executable files... Got a good reference after long search I got Installing MongoDB in Windows
After Installing open command prompt and type "mongod", then keep the window minimized and open another command prompt window and type "mongo" and you will find the success message of connecting to the test database.
hope it helps

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-
Go to C drive, make a folder named data and inside that create another folder named db.
Now move to directory where monodb server is installed. Go to C:\Program Files\MongoDB\Server(Version)\bin. Copy this file location.
To make it easier to run server in future, press windows key and type environment variables.
You will see an option 'Edit the system environment variables'.
On the lower right corner, you will see a button 'Environment Variables...'. Click that.
Under System variables, double click on path.
Click on new and paste the file location you copied earlier.
Now open cmd, and type mongod.exe (It's a daemon which hosts the server.)
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.

Actually windows way to use service, from the official documentation:
Find out where is your executable is installed, path may be like this:
"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe"
Create config file with such content (yaml format), path may be like this:
"C:\Program Files\MongoDB\Server\3.4\mongod.cfg"
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
Execute as admin the next command (run command line as admin):
C:\...\mongod.exe --config C:\...\mongod.cfg --install
Where paths is reduced with dots, see above.
The key --install say to mongo to install itself as windows service.
Now you can start, stop, restart mongo server as usual windows service choose your favorite way from this:
from Control Panel -> Administration -> Services -> MongoDB
by command execution from command line as admin: (net start MongoDB)
Check log file specified in config file if any problems.

This is ALL I needed to init mongo in PowerShell, many replies are IMO too sophisticated.
Install: https://www.mongodb.com/download-center#community
Add C:\Program Files\MongoDB\Server\3.6\bin to environmental
variable "path". Notice: this version will be outdated soon.
Turn on new PowerShell, as it gets environmental variables on a
start, then type mongod
Open another PowerShell window and type mongo - you have access to mongo REPL! If you don't, just repeat 4 again (known bug: https://jira.mongodb.org/browse/SERVER-32473)

Clearly many people have answered upon your query of how to make mongoDb work,
I'd answer the second part: Regarding an appropriate GUI for mongoDB
My suggestion is, go for MongoChef (now Studio 3T)
You can easily install and use it.
You might want want to refer to (from 03:10- to 08:50):
https://www.youtube.com/watch?v=0ws3oIyqieY&index=2&list=PLS1QulWo1RIZtR6bncmSaH8fB81oRl6MP
For a step by step guide to the GUI tool.

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:

Restart your cmd
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

You can start Mongo also as a Win Service!
Start
Stop

Related

BadValue: error: no args for --configdb try 'C:\Program Files\MongoDB\Server\6.0\bin\mongos.exe --help' for more information

I finished installing MongoDB and I am trying the command $ mongo and I keep getting an error:
BadValue: error: no args for --configdb try 'C:\Program Files\MongoDB\Server\6.0\bin\mongos.exe --help' for more information
I think you might have set up the config server as a standalone process and you might have to use a replicaset instead.
This might help:
https://www.mongodb.com/docs/manual/sharding/
Your command will look something like this:
mongos --configdb replsetname/localhost:27010 --port 27011
But if you are trying to use the mongoDb shell then you might have to download it separately. They do not bundle the shell together as they used to before. So you have to download mongosh as a zip and extract the contents of the "bin" folder to the "bin" folder where you have installed mongo. Then you can use the MongoDB shell(mongosh.exe).
You need to install mongos shell separately. It can be downloaded as a zip file you need to extract it to the program files. Then add the location of mongos.exe to the vim.
If you face any difficulty in adding the path to vim use this link.
Make sure to change the version in the path example, mine will look like this.
alias mongod="/c/Program\ Files/MongoDB/Server/6.0/bin/mongod.exe"
alias mongos="/c/Program\ Files/mongosh-1.6.1-win32-x64/mongosh-1.6.1-win32-x64/bin/mongos.exe"
Don't make an exact copy of this. Change the path according to your setup and add these values in vim and close it using
:wq!
Use the provided link for handling the vim.

When can I use the command 'mongod' in Command Line?

I recently installed the version 4.4 of MongoDB,I followed all the instructions as in the documentation of mongodb.
As instructed by my tutor I created another folder named 'mongodb'in my pc,inside which I created another folder named 'data' as well.Now i went to the command prompt and entered into the same mongodb folder i created earlier and typed the following command.
C:\Users\Dell\mongodb>mongod --dbpath=data --bind_ip 127.0.0.1
When I press Enter I see an error :
'mongod' is not recognized as an internal or external command,operable program or batch file.
I am totally stuck in this.I even reinstalled mongodb again,but it is not working.
You might have a problem with path in Mongodb. After the installation process ends open a
Command Interpreter with Administrative privileges and run:
"C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe"
Now afterward you can use the 'mongod' Command. If still you are unable go to the pre insatlled Mongodb folder copy the path upto bin .
Now go to :
controlpanel>system and security>system>Advanced system settings.
A dialogue box appears and then at the bottom there is the option for Environment Variables.Click on that.
If Mongodb variable already exit delete that and click on the path option. You might see a new option somewhere around click on that and input box appears.Now paste the copied path in that box and click save/Ok or sth to end the options.
Now you can use the 'mongod' command .

mongod and mongo commands not working on windows 10

I've installed mongoDB on my windows 10 OS. Then I tried setting its database path to some directory by moving to it and typing mongod --datapath=data in cmd, where data is the folder which is to contain the db(I've used the relative path because I'm in that directory). But message comes that mongod is unrecognized command. After some searching I found that by specifying mongod path, i.e. "C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --datapath=data works. Similar thing happens for mongo.
I want to directly run mongod and mongo commands, I have seen people directly using it(without going to the directory or specifying the path).
For a Windows installation, by default you have to use the full path to the exe unless you add it to the PATH.
To add it to the PATH:
01) Get path to bin, something like: C:\Program Files\MongoDB\Server\4.0\bin
02) Press the Windows key, type env, select Edit the system environment variables
03) On the Advanced tab, click Environment Variables
04) In the User variables for xxxx section, select path and then click the Edit... button
05) Click New and paste your path with a trailing slash, eg:
C:\Program Files\MongoDB\Server\4.0\bin\
06) Click OK, OK, OK and restart your command window.
Source
The examples you have seen are probably based on UNIX installations which I think by default install mongo as a service (which Windows doesn't) and that is what is called in those examples.
To simplify startup and configuration on Windows, you can also install it as a service. See the Mongo documentation here and the
"Configure Windows Service for MongoDB' section".
This will then allow you to start and stop Mongo by simply calling
net start MongoDB
Or
net stop MongoDB
If installed MongoDB version is 6.0 or above, mongo command will not work on Powershell/cmd. If you run the command you will get the following error:
'mongo' is not recognized as an internal or external command,
operable program or batch file.
To run mongo commands, you have to install MongoDB Shell from
After installing the shell, extract the zip file, you can rename the extracted folder (mongosh-1.6.0-win32-x64) as "MongoDB Shell" and move that folder to Windows(:C) > Program Files
Now open the folder, go to bin and copy the path:
C:\Program Files\MongoDB Shell\mongosh-1.6.0-win32-x64\bin (or
C:\Program Files\mongosh-1.6.0-win32-x64\mongosh-1.6.0-win32-x64\bin)
Go to
Settings > System > About > Advanced system settings > Environment
Variables > Under System Variables, click on 'Path' then 'Edit' >
Click 'New' and paste the above copied path > Click 'Ok' 'Ok' 'Ok'
Now open Powershell/cmd, run the command 'mongosh'
You're all set to work with MongoDB
To add it to the PATH:
Add Mongo’s bin folder to the Path Environment Variable
Kindly check the link:
here
After adding bin folder to the path Environment Variable
then simply type mongo in terminal it will start working
reference : Microsoft document
set your path like this
;C:\Program Files\MongoDB\Server\4.0\bin
this is worked for me.
Based on welshGaz answer above, I edited the User Path variable but it did not work for me yet. I wasn't able to access the System Path variables.
What I noticed from the errors on the command prompt is that it what missing the "C:\data\db" directory to store its files (I don't know what those files are for just yet). So I created that directory myself and it worked.
Same problem here. I installed through the .msi file provided for windows X64bit. In the installer instructions from MongoDB (https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/), I read that you can add C:\Program Files\MongoDB\Server\4.2\bin to the System Path. Then it asks to omit the full path to the the MongoDB binaries. That is where I think some information is missing. How are we supposed to omit the full path to the MongoDB binaries?
Currently I can get MongoDB to run mongod using:
"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --dbpath="c:\data\db"
For --dbpath="c:\data\db" you can replace "c:\data\db" with the path to your database.
I can also run mongo using:
"C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe"
Another reason to it if you enabled any property in YAML file and it is not formatted properly. YAML looks for specific syntax like colon":"+space" ".
E.g.-
security:
authorization: enabled
use mongosh command from your terminal. mongo command no longer works for 6.0 and above.
if you are trying to connect from connection url eg mongodb://localhost:27017/yourdb try changing it to something like mongodb://127.0.0.1/yourdb

Failed Global Initialization: BadValue logpath requires an absolute file path with windows services

I am getting this error constantly while i am trying to install mongod using a configuration file. So, I am looking at this tutorial on Pluralsight on mongodb. The person's programming environment going as smoothly as it can. However, i am encountering several problems. First of all, i am trying to setup a different logpath and database path.This is the basic layout of the conf file
dbpath=/Pluralsight/db
logpath=/Pluralsight/mongod.conf
verbose=vvvvv
My syntax:
c:\Program Files\MongoDB\Server\3.0\bin\mongod -f c:\Pluralsight\mongod.conf
//Trying to run mongod using a configuration file
When i press enter, i am supposed to get a message that says everything is being directed to this new logfile and a new database. I do not get any message. However, that did not stop it from creating a log file with information in the expected folder. Now, I proceed to install mongod as a service. This is when i type
C:\Program Files\MongoDB\Server\3.0\bin\mongod -f c:\Pluralsight\mongod.conf --install
//using the configuration file to install mongod as a service
I get an error:
Failed Global Initialization: BadValue logpath requires an absolute
file path with windows services
I have no idea how to fix this!
I was having the same problem with MongoDB's instructions because I was using relative path in the CLI for my mongo.cfg once I had navigated to the MongoDB bin:
mongod.exe --config mongod.cfg --install.
Instead I needed to specify the config file's absolute path:
mongod.exe --config "C:\Program Files\MongoDB\Server\3.0\bin\mongod.cfg" --install
The error message spells out the problem. Your MongoDB confguration file has a relative path, not an absolute path.
Try setting the logpath as follows
logpath=c:/Pluralsight/mongod.log
I got the same problem. After I read this doc, resolved.
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows
Open an Administrator command prompt.
Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator.
Execute the remaining steps from the Administrator command prompt.
Create directories.
Create directories for your database and log files:
mkdir c:\data\db
mkdir c:\data\log
Create a configuration file.
Create a configuration file. The file must set systemLog.path. Include additional configuration options as appropriate.
For example, create a file at C:\mongodb\mongod.cfg that specifies both systemLog.path and storage.dbPath:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
Install the MongoDB service.
Important
Run all of the following commands in Command Prompt with “Administrative Privileges”.
Install the MongoDB service by starting mongod.exe with the --install option and the -config option to specify the previously created configuration file.
"C:\mongodb\bin\mongod.exe" --config "C:\mongodb\mongod.cfg" --install
To use an alternate dbpath, specify the path in the configuration file (e.g. C:\mongodb\mongod.cfg) or on the command line with the --dbpath option.
If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service with a unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient system resources exist and your system design requires it.
Start the MongoDB service.
net start MongoDB
Stop or remove the MongoDB service as needed.
To stop the MongoDB service use the following command:
net stop MongoDB
To remove the MongoDB service use the following command:
"C:\mongodb\bin\mongod.exe" --remove
echo logpath=C:/myProgra/MongoDB/log/mongo.log > "C:\MyProgram\MongoDB\mongod.cfg"
C:\myprogram\MongoDB\Server\3.0\bin\mongod.exe --config "C:\myProgram\MongoDB\mongod.cfg" --install
I ran into the same problem. But I could resolve it by updating the paths as follows. I could see the problem is with Forward and backward slashes in file paths.
mongod.conf (instead of giving the relative path provide absolute path and also make sure you have "/" instead of "\")
dbpath= C:/mongolearning/db
logpath= C:/mongolearning/mongo-server.log
verbose=vvvvv
and then go to Command prompt:
C:\Program Files\MongoDB\Server\3.2\bin>mongod -f "C:\Program Files\MongoDB\Server\3.2\bin\mogod.conf" --install
and then
C:\Program Files\MongoDB\Server\3.2\bin>net start mongodb
Boom it started.
The MongoDB service is starting.
The MongoDB service was started successfully.
I faced the same problem while installing the MongoDB service by specifying the logpath and dbpath flags directly from the command line.
mongod --install --logpath='<my log path>' --dbpath='<my db path>'
It turned out that the logpath and dbpath values had to be wrapped inside double quotes (i.e. "") instead of single qoutes, or otherwise no quotes at all if the paths are without any spaces in the absolute directory path.
So the following did the trick for me:
mongod --install --logpath="<my log path>" --dbpath="<my db path>"
Notice the paths wrapped within double qoutes.
Thanks for the suggestions guys. I just went with MongoDB's instructions on their website on installing mongod as a service in windows instead of Pluralsight tutorial's and it went well.
there can't be quotation marks in your configure file .
way like this is wrong:
dbpath="D:/Program Files/MongoDB/Data/DB"
logpath="D:/Program Files/MongoDB/Data/Log/mongo.log"
downside is right:
dbpath=D:/Program Files/MongoDB/Data/DB
logpath=D:/Program Files/MongoDB/Data/Log/mongo.log
In the config file use absolute path instead of relative path for dbpath & logpath as like below and run the command to install the MongoDB service.
dbpath = c:/Pluralsight/db (instead of /Pluralsight/db)
logpath = c:/Pluralsight/mongo-server.log (instead of Pluralsight/mongo-server.log)
verbose = vvvvv
Command to install the MongoDB service is like:
mongod -config "C:\Pluralsight\mongod.conf" --install
I got the same error
**Failed Global Initialization: BadValue logpath requires an absolute file path with windows services**
as I was specifying log path folder in mongo.config but I have to specify a log file
dbpath=C:\Program Files\MongoDB\Server\3.4\data\db
logpath=C:\Program Files\MongoDB\Server\3.4\log
diaglog=3
i changed my log file to
dbpath=C:\Program Files\MongoDB\Server\3.4\data\db
logpath=C:\Program Files\MongoDB\Server\3.4\log\mongo.log
diaglog=3
and after that this command solved my problem. hope this workfor you as well.
mongod.exe --config "C:\Program Files\MongoDB\Server\3.4\mongo.config" --install
then finally
net start MongoDB

Can not access MongoDB in command prompt by using command --dbpath

I can not access MongoDB in my command prompt even if i have already set path in environment variables path setting.I have installed MongoDB in my c drive.i created one new folder and copied its path.I oped command prompt and typed command mongod --dbpath folder-path-name and when run this it gave me the error mongod is not internal or external command.In one of my win-7 systme it is running nicely.But here i tried in windows-8 system.Please help me to resolve this issue.