Connection timeout when writing to Cosmos Db with MongoDb.NET Driver

Greg Quinn 96 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]");  
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?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,058 questions
{count} votes

Accepted answer
  1. Greg Quinn 96 Reputation points

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful