The PyMongo library allows interaction with the MongoDB database through Python; it is a native Python driver for MongoDB.
PyMongo supports the following MongoDB versions:
PyMongo can be installed using pip:
pip install pymongo
If you’re using pip with Python3, run:
pip3 install pymongo
Have a look at a basic example below on how to get started with PyMongo:
import pymongo# To create a database in MongoDB, start by creating a MongoClient object,# then specify a connection URL with the correct ip address# and the name of the database you want to create.client = pymongo.MongoClient("mongodb://localhost:27017/")# Create a database called "MyDB"mydb = myclient["MyDB"]
In MongoDB, a database is not created until it gets content.
MongoDB waits until you have created a collection with at least one record before it creates the database.