I resolved this issue by removing the MongoDb .NET connector, and instead installed the Microsoft.Azure.Cosmos NuGet package.
I could then write to the database without any issues.
Connection timeout when writing to Cosmos Db with MongoDb.NET Driver
Greg Quinn
116
Reputation points
I have an Azure function, I can connect to my CosmosDb in Azure fine, and even get the database.
var client = new MongoClient("mongodb://stor-cosmos-db:[MY_PRIMARY_ACCOUNT_KEY]@stor-cosmos-db.documents.azure.com:443/?ssl=true");
var database = client.GetDatabase("stor-db2");
When debugging my code, I get back values from these two rows, so it seems the connection is valid.
But as soon as I try to write something to the database, it just times out...
await database.CreateCollectionAsync("raceresult", new CreateCollectionOptions
{
Capped = true,
MaxSize = 1024,
MaxDocuments = 10,
});
I get the value for MY_PRIMARY_ACCOUNT_KEY from the Read/Write keys in the Azure Portal.
So if these are read/write keys, why do I get a timeout after 30 seconds whenever I try to write something?
Accepted answer
-
Greg Quinn 116 Reputation points
2021-09-28T22:35:34.227+00:00