You can use pymongo to connect to the MongoDB database. You have to first import the MongoClient and then you have to create a connection with the database, refer to the following code:
from pymongo import MongoClient
client = MongoClient()
Then fetch your database instance and collection with the help of the following code:
Learn about full stack web development by signing up for this professional Full Stack Training offered by Intellipaat..
db = client.my_database
collection = db.my_collection