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

时间:2024-10-10 15:22:57

连接代码

  • SSL开启
    import ssl
    from pymongo import MongoClient
    conn_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 ssl
    from pymongo import MongoClient
    conn_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/qs-dds/dds_02_0090.html