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
전문가
질문됨 8달 전56회 조회
1개 답변
0

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

profile picture
전문가
답변함 8달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인