To establish a connection to a MongoDB database, import the connector and use the connect() method with your connection parameters.
First, import the MongoDB connector module:
import devart.mongodb as mongodb
Call the connect() method and obtain a connection object.
my_connection = mongodb.connect(
Server="your_server",
Database="your_database",
Username="your_username",
Password="your_password",
ClientLibary="path_to_libmongoc",
BSONLibrary="path_to_libbson"
)
Replace the example values with your actual connection values.
For more information, see Connection parameters.