Connecting MongoDB With Python

Database Image
  1. What is MongoDB
  2. Using MongoDB with Python using pymongo.
  1. Whenever we speak about Database (DB) there is one common DB that comes to mind — MySQL. This is a Relational Database. These basically use tables to describe the relationship between data.
  2. On the other hand, are NoSQL database which doesn't use a table for describing the relationship, rather they can use document-based, key-value pairs, etc. Moreover, unlike SQL, they have a dynamic schema, while SQL has a well-defined schema.
pip install pymongo
pip install dnspython
# Install driver for python to connect to MongoDB
import pymongo
from pymongo import MongoClient
client = MongoClient("Enter your connection string")
# Print Name of all Databases
print("\n The Name of all Databases are : ")
# Connect to a Database
db = client.database_name
# Print Name of all Connections in the Database
print("\n The Name of all Connections in the Database are : ")
collection = db.collection_namequery ={
for document in collection.find(query):
{“tag1”: True, “tag2”: False, “tag3”:” Adnan”, “tag4”: 5}




Full-Stack Data Scientist

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building A Connected Game With Expo

How To Pass the AWS Certified Solutions Architect— Associate Exam

8 Tips for Choosing the Right Mobile App Development Company

Smalish Post 1

Run Jupyter Lab on a Remote Server

eGame x Satoshi Club AMA Recap from the 30th of September

What Ruby taught me

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adnan Karol

Adnan Karol

Full-Stack Data Scientist

More from Medium

Deploying Keras Models Using Flask And SQLAlchemy

Easier Python Package Deploying

The Different Types of Constraints Available in PostgreSQL & How to Use Them on the Table

How to run PostgreSql using Docker and Python