Installing MongoDB on Windows with Python - GeeksforGeeks

06 Oct, 2021
We would explain the installation of MongoDB in steps. Before you install, I would suggest everyone use ide spyder, Anaconda.
Step 1 -> Install the community EditionInstallation Link
Step 2 -> Run the installed MongoDB windows installer package that you just downloaded.
MongoDB get installed here->
C:\Program Files\MongoDB\Server\3.4\
Step 3 -> Let’s set MongoDB environment
(a) Create data directory where all data is stored.On C: drive create a folder data inside it create a folder dborRunmd C:\data\db
md C:\data\db
(b) To start MongoDBRun ->"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe"
Wait till the connection message appears
"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe"

Wait till the connection message appears
(c) Verify Environment Path or set path if not correctly setOpen environment variables, you can search this by windows search.Open Environment Variable under the System variables section open Path.This would look like this.Add the path of bin folder as shown in the image above.
(c) Verify Environment Path or set path if not correctly setOpen environment variables, you can search this by windows search.
Open Environment Variable under the System variables section open Path.This would look like this.Add the path of bin folder as shown in the image above.
(d) To Connect to MongoDBOpen other command prompt and run->"C:\Program Files\MongoDB\Server\3.4\bin\mongo.exe

(d) To Connect to MongoDBOpen other command prompt and run->
"C:\Program Files\MongoDB\Server\3.4\bin\mongo.exe

Step 4-> Ready MongoDBOpen Command Prompt(Admin mode) type->
mongod
NOTE : Till step 4 MongoDB will work only when the Command Prompt is open and it’s listening.Now we’ll see Extension to make it better.
Below steps from step 5 to step 8 are optional :Step 5-> Open command prompt and run-
mkdir c:\data\db
mkdir c:\data\log

Step 6-> Create a configuration file at C:\Program Files\MongoDB\Server\3.4\mongod.cfg (name of file mongod.cfg)
systemLog:
    destination: file
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db

This can be created and saved in Admin mode of Notepad or Notepad++ or any other editor to run notepad admin mode press Ctrl + Shift + Enter. Admin mode of notepad will let you create mongod.cfg and save above text file.
Step 7 -> Install the MongoDB service by starting mongod.exe with the –install option and the -config option to specify the previously created configuration file.Now run this command on command prompt
"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" 
--config "C:\Program Files\MongoDB\Server\3.4\mongod.cfg" --install
Step 8-> To start & stop MongoDB runTo start :
net start MongoDB
To stop :
net stop MongoDB

NOTE : ALL commands are run on Command Prompt Admin mode, to open command prompt Admin Mode either open normal command prompt and press Ctrl+Shift+Enter or Right click on left windows icon start button where you can see the options.Step 9 -> Open Anaconda Command Prompt as shown in the image.
Step 10 -> Install package to use MongoDBTo install this package with conda run:
conda install -c anaconda pymongo 

Congratulations!! Installation completed.( Pymongo works only when MongoDB is started, use net start MongoDB to start it and then work on spyder)You can study and understand MongoDB in python here.
This article is contributed by SHAURYA UPPAL. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
how-to-install
Python-mongoDB
GBlog
Installation Guide
Python
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, ...
DSA Sheet by Love Babbar
Socket Programming in C/C++
GET and POST requests using Python
Must Do Coding Questions for Product Based Companies
How to Install PIP on Windows ?
Installation of Node.js on Linux
How to install Jupyter Notebook on Windows?
How to Install FFmpeg on Windows?
How to Install Anaconda on Windows?