Document Database Service

Connect using mongo driver

2025-07-28 06:38:04

The DDS instance supports drivers in multiple programming languages. Users can download the corresponding driver for development according to the programming language they use.

Taking Python language as an example, this section describes how to connect to DDS.

First, install the pymongo library on the machine, then use the pymongo library to connect to the instance in Python code and execute the isMaster command. Example:

#!/bin/env python
#-*-coding:utf-8-*-
import pymongo
if __name__ == '__main__':
    client = pymongo.MongoClient("<replace with instance IP>", <replace with instance port>)
    client.admin.authenticate("root", "xxxxxxx")
    res = client.admin.command("isMaster")
    print(res)
    client.close()


2NswsZ.bQONI