title: Programmatically enable sharding + choosing shard key on a collection using casbah with Mongo 2.4
body: <p>I am attempting to programmatically "enable sharding" and set the "shard key" using java/scala API particularly casbah</p>
  
  <p>Our config</p>
  
  <pre><code>scala 2.10
  casbah 2.6 - "org.mongodb" % "casbah_2.10" % "2.6.0",
  MongoDB 2.4.4
  </code></pre>
  
  <p>Also what is the casbah driver version for mongo 2.4.4 (with scala 2.10)</p>
  
  <p>Our use case is such that, collections + indexes are created programmatically using the casbah scala API <code>dbConnection.getCollection(....)</code> and    <code>collection.ensureIndex(DBObject("orgId" -&gt; 1), DBObject("background" -&gt; true, "name" -&gt; "org_idx", "unique" -&gt; false))</code></p>
  
  <p>Is there an equivalent casbah API to programmatically, enableSharding and choose shardKey as well as we are currently sharding our mongo cluster to scale out.
  Our database + collection names are not known ahead time and a dynamically created using API, so a enabling sharding using mongo shell is simply not an option.</p>
  
  <p>Is there a better way to do this ? ANy recommendations?</p>