Guide to Install MongoDB with Python in Windows


Get MongoDB

To install MongoDB on Windows, first, download the latest release of MongoDB from https://www.mongodb.org/downloads. Below is an example of selecting a 64-bit version for windows as a msi installer.

Install MongoDB

Next, we follow the below steps to install MongoDB. As it is a windows installation using the msi installer, the steps are very straight forward. We choose a complete installation instead of a custom installation.

Running the installer

Here we run the installer which has been downloaded to our system. The installation starts asking for various steps of confirmation.

Choosing a Service Configuration

We choose to run the service as a network service user.

 

Clicking on the subsequent next buttons we reach the finish screen which confirms the installation.

Checking the installation

We can verify the installation by running the MongoDB service. In the below screen we use the mongo.exe command located under program files. In response we see the MongoDB server running.

 

Installing Python Driver

We install the python driver so that python can interact with MongoDB. For this, we go to the python environment already installed in windows and add the package pymongo. The command to do this is shown below.

pip install pymongo

Verifying connectivity with Python

In the below example we connect python to MongoDb and fetch the result for information on systems database.

import pymongo

myclient = pymongo.MongoClient("mongodb://localhost:27017/")

#mydb = myclient["mydatabase"]
print(myclient.list_database_names())

Running the above code gives us the following result:

['admin', 'config', 'local']

Updated on: 17-Oct-2019

422 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements