title: Copying a mongo collection using Java Driver
body: <p>I want to copy the contents from one collection to another.</p>
  
  <p>in mongod this can be done:</p>
  
  <pre><code>db.tempMongoItem.find().forEach( function(x){db.mongoItem.insert(x)} )
  </code></pre>
  
  <p>Using Java Mongo Driver, I try:</p>
  
  <pre><code>DB db = mongoClient.getDB("mydb")
  </code></pre>
  
  <p>CommandResult result = db.command("db.tempMongoItem.find().forEach( function(x){db.mongoItem.insert(x)} )")</p>
  
  <p>But I get:</p>
  
  <pre><code>result = [serverUsed:localhost:27017, ok:0.0, errmsg:no such cmd: db.tempMongoItem.find().forEach( function(x){db.mongoItem.insert(x)} ), code:59, bad cmd:[db.tempMongoItem.find().forEach( function(x){db.mongoItem.insert(x)} ):true]]
  </code></pre>
  
  <p>Any ideas?</p>