lambda - 无法从DocumentDb获取数据库名称

0

【以下的问题经过翻译处理】 我正在尝试获取我的DocumentDB的数据库名称列表。我正在使用pymongo库。 我运行了这段代码;

logging.info("get client")
    #connectionString = os.environ["documentdb_connection"]
    connectionString = "mongodb://geoff:qzmpqzmp@docdb-2023-03-22-20-49-15.cluster-cwl5gnwixa5k.us-east-1.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false"
    ##Specify the database to be used
    logging.info("Get database testdb")
    #db = client.testdb
    logging.info("All the databases")
    #db = client.testdb
    logging.info(client.list_database_names())

我无法连接到我想要的特定数据库,因此我打算注释掉那些行,而是列出所有的数据库,以检查它是否存在。在代码的最后一行中,我得到一个NameError; “name'client'未定义” 我该怎么办?

profile picture
EXPERTO
preguntada hace 8 meses57 visualizaciones
1 Respuesta
0

【以下的回答经过翻译处理】 在尝试使用它之前,你忘记了创建客户端对象。你应该使用pymongo库中的MongoClient类来创建连接。

profile picture
EXPERTO
respondido hace 8 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas