文档数据库服务 DDS-Python示例:连接代码

时间:2025-01-26 10:50:28

连接代码

  • SSL开启
    import sslfrom pymongo import MongoClientconn_urls="mongodb://rwuser:rwuserpassword@ip:port/{mydb}?authSource=admin"connection = MongoClient(conn_urls,connectTimeoutMS=5000,ssl=True, ssl_cert_reqs=ssl.CERT_REQUIRED,ssl_match_hostname=False,ssl_ca_certs=${path to certificate authority file})dbs = connection.database_names()print "connect database success! database names is %s" % dbs
  • SSL关闭
    import sslfrom pymongo import MongoClientconn_urls="mongodb://rwuser:rwuserpassword@ip:port/{mydb}?authSource=admin"connection = MongoClient(conn_urls,connectTimeoutMS=5000)dbs = connection.database_names()print "connect database success! database names is %s" % dbs
support.huaweicloud.com/usermanual-dds/dds_03_0358.html