Skip to content

Instantly share code, notes, and snippets.

@zleao
Last active July 14, 2020 12:03
Show Gist options
  • Save zleao/872799968d06039b5739aad5d84d3498 to your computer and use it in GitHub Desktop.
Save zleao/872799968d06039b5739aad5d84d3498 to your computer and use it in GitHub Desktop.
Create sharded collections with MongoDB.Driver
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