Last active
July 14, 2020 12:03
-
-
Save zleao/872799968d06039b5739aad5d84d3498 to your computer and use it in GitHub Desktop.
Create sharded collections with MongoDB.Driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var partitionKey = "_id"; | |
var partition = new BsonDocument { | |
{"shardCollection", $"{Database.DatabaseNamespace.DatabaseName}.{collectionName}"}, | |
{"key", new BsonDocument {{partitionKey, "hashed"}}} | |
}; | |
var command = new BsonDocumentCommand<BsonDocument>(partition); | |
await Database.RunCommandAsync(command); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment