Complete a 3 Question Survey and Earn a re:Post Badge
Help improve AWS Support Official channel in re:Post and share your experience - complete a quick three-question survey to earn a re:Post badge!
【以下的问题经过翻译处理】 我正在尝试获取我的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'未定义” 我该怎么办?
【以下的回答经过翻译处理】 在尝试使用它之前,你忘记了创建客户端对象。你应该使用pymongo库中的MongoClient类来创建连接。
您未登录。 登录 发布回答。
一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。