Learn practical skills, build real-world projects, and advance your career

MongoDB: A NoSQL Database

image

  • Installing MongoDB Server and MongoDB Compass Locally
  • create a new python environment and install PyMongo
  • Read the Database using PyMongo commands(functions and methods)
  • Use CRUD Operations using PyMongo in a jupyter notebook
  • Conclusion

Note: Please run this notebook locally, and do install MongoDB community server in your system before running this notebook.

To install MongoDB in your system locally, follow the steps:

  • Go to MongoDB official website
  • Go to product =>Community Edition section
  • Select On Premises locally
  • Select MongoDB Community Server
  • Select the appropriate version and platform that you want to install and download the .msi file

MongoDB

Once the file gets downloaded, you can now run into the MongoDB setup wizard, accept all the Terms and Conditions, do check on complete installation, and also tick on the installing MongoDB Compass, it will install MongoDB Compass in your system. (This is optional, but do install Compass if you are a beginner, if you skip this now, you can install it later)

There are ways to use and manipulate database:

  • You can manipulate the data using MongoDB Shell using shell commands
  • You can manipulate the data using MongoDB Compass manually
  • You can manipulate using external application using other languages such as Django, JavaScript, Python and etc.

Note: In this tutorial we will be using Python Only
image

PyMongo

To manipulate MongoDB databses using Python there is a package called PyMongo, that you can install using the following command:

  • !pip install pymongo --upgrade --quiet on jupyter notebook
  • conda install pymongo on conda command shell

If you want to install PyMongo for a specific database with certain dependencies then there are some more ways to install PyMomgo with dependencies. You will get the ways to install pymongo with dependencies here

!pip install pymongo --upgrade --quiet
# Importing PyMongo package along with Pandas and Numpy
import pandas as pd
import numpy as np
import pymongo