Search code examples
c++mongodbshardingmongo-cxx-driver

Enable sharding mongocxx


I wonder how to execute these command by using mongocxx 3.1.3 (Mongo C++ driver):

sh.enableSharding("YourDB")
sh.shardCollection("YourDB.YourCollection", {field:hashed})

I've searched for 3 hours and still not find out the way. Any idea?


Solution

  • The driver doesn't offer helpers for this, but you can invoke the command on the server by using mongocxx::database::run_command with arguments as specified in the manual for the enableSharding command.