1 Answer
- Newest
- Most votes
- Most comments
4
you forgot to create the client object before attempting to use it. You should use the MongoClient class from the pymongo library to create a connection
example code:
import logging
import os
from pymongo import MongoClient
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"
# Create the client
client = MongoClient(connectionString)
##Specify the database to be used
logging.info("Get database testdb")
#db = client.testdb
logging.info("All the databases")
#db = client.testdb
# List all database names
logging.info(client.list_database_names())
Relevant content
- asked 3 months ago
- asked 9 months ago
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 7 months ago
Oh dear, I must have deleted that line by mistake. anyway thank you very much!