I am trying to develop a RAG using AzureOpenAI and CosmosDB
I have created a Azure Cosmos DB for MongoDB (vCore) in azure. I am trying to connect to the db but getting ServerSelectionTimeoutError.
I am Set up the connection through below python code:
from urllib.parse import quote_plus
username = quote_plus("username")
password = quote_plus("password")
server = "service_name.mongocluster.cosmos.azure.com"
mongo_conn = f"mongodb+srv://{username}:{password}@{server}/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000"
mongo_client = pymongo.MongoClient(mongo_conn)
This code runs successfully with below warning:
C:UsersAppDataLocalTempipykernel_329224156620.py:9: UserWarning: You appear to be connected to a CosmosDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/cosmosdb
mongo_client = pymongo.MongoClient(mongo_conn)
Then I try to execute the below code for Set up the DB and collection
# create a database called TryDB
db = mongo_client['TryDB']
# Create collection if it doesn't exist
COLLECTION_NAME = "Try_Collection"
collection = db[COLLECTION_NAME]
if COLLECTION_NAME not in db.list_collection_names():
# Creates a unsharded collection that uses the DBs shared throughput
db.create_collection(COLLECTION_NAME)
print("Created collection '{}'.n".format(COLLECTION_NAME))
else:
print("Using collection: '{}'.n".format(COLLECTION_NAME))
This code block gives me below error:
ServerSelectionTimeoutError: c.service_name.mongocluster.cosmos.azure.com:10260: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: 627, topology_type: Unknown, servers: [<ServerDescription (‘c.service_name.mongocluster.cosmos.azure.com’, 1020) server_type: Unknown, rtt: None, error=NetworkTimeout(‘c.service_name.mongocluster.cosmos.azure.com:1020: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)’)>]>
Murphy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.