Skip to content

Commit c52ac51

Browse files
authored
Merge pull request #95963 from sandeepsnairms/MongoCreateContainerNetSDKBug
Error in Command to Create Container using .Net fixed
2 parents fd0276c + 8dd65fa commit c52ac51

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

articles/cosmos-db/mongodb/how-to-create-container-mongodb.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ This article explains the different ways to create a collection in Azure Cosmos
4343
## <a id="dotnet-mongodb"></a>Create using .NET SDK
4444

4545
```csharp
46-
// Create a collection with a partition key by using Mongo Shell:
47-
db.runCommand( { shardCollection: "myDatabase.myCollection", key: { myShardKey: "hashed" } } )
46+
var bson = new BsonDocument
47+
{
48+
{ "customAction", "CreateCollection" },
49+
{ "collection", "<CollectionName>" },//update CollectionName
50+
{ "shardKey", "<ShardKeyName>" }, //update ShardKey
51+
{ "offerThroughput", 400} //update Throughput
52+
};
53+
var shellCommand = new BsonDocumentCommand<BsonDocument>(bson);
54+
// Create a collection with a partition key by using Mongo Driver:
55+
db.RunCommand(shellCommand);
4856
```
4957

50-
> [!Note]
51-
> MongoDB wire protocol does not understand the concept of [Request Units](../request-units.md). To create a new collection with provisioned throughput on it, use the Azure portal or Cosmos DB SDKs for SQL API.
52-
5358
If you encounter timeout exception when creating a collection, do a read operation to validate if the collection was created successfully. The read operation throws an exception until the collection create operation is successful. For the list of status codes supported by the create operation see the [HTTP Status Codes for Azure Cosmos DB](/rest/api/cosmos-db/http-status-codes-for-cosmosdb) article.
5459

5560
## <a id="cli-mongodb"></a>Create using Azure CLI

0 commit comments

Comments
 (0)