I just want to add that Julias answer is correct, but now it is out of date. You can use the new API ( Document
class from org.bson
package):
MongoDatabase database = client.getDatabase("admin"); Document documentA = database.runCommand(new Document("enablesharding", "test")); Document documentB = database.runCommand( new Document("shardcollection", "testDB.x").append("key", new Document("userId", 1)));
source share