Hi @Iulian_Nitescu,
Sharding a collection is usually considered an administrative task that users would do once using the shell or another tool, so drivers don’t offer a helper for it. You can do this using db.RunCommand. The command document should be based on the information at https://docs.mongodb.com/manual/reference/command/shardCollection/. It would look something like this:
cmd := bson.D{
{"shardCollection", "dbName.collectionName",
{"key", bson.D{{"firstKeyField", 1}, {"secondKeyField", 1}, ...},
{"unique", true},
{"numInitialChunks", 5},
}
err := db.RunCommand(ctx, cmd).Err()
// handle error
– Divjot