title: Upgrading mongo search from runCommand to find using Java driver
body: <p>I am using a Java driver to run some mongo text searches.
  An example of my previous code is (where values is a String passed in):</p>
  
  <pre><code>DBCollection coll = db.getCollection("testCollection");
  //create the basic object
  DBObject searchCmd = new BasicDBObject();
  //create the search cmd
  searchCmd.put("text", "testCollection"); // the name of the collection (string)
  // define the search word
  searchCmd.put("search", value); // the term to search for (string)
  // define the return values
  searchCmd.put("project", new BasicDBObject("score", 1).append("name", 1).append("path", 0).append("_id", 0));
  // get the results
  BasicDBObject commandResult = db.command(searchCmd);
  // Just out the results key
  BasicDBList results = (BasicDBList) commandResult.get("results");
  </code></pre>
  
  <p>then I loop over the "results" and I get for each it score by </p>
  
  <pre><code>// Get the number ii
  BasicDBObject element = (BasicDBObject) results.get(ii);
  // Now get the score
  double score = (double) element.get("score");
  </code></pre>
  
  <p>I want to upgrade to use find since that seems the way 2.6 and later prefers it. So far I have:</p>
  
  <pre><code>DBCollection coll = db.getCollection("testCollection");
  BasicDBObject query = new BasicDBObject();
  query.append("$text", new BasicDBObject("$search", value));
  DBCursor cursor = coll.find(query);
  </code></pre>
  
  <p>However, I am not sure how to get the score.
  I tried doing something like:</p>
  
  <p>query.append("score", new BasicDBObject("$meta", "textScore"));</p>
  
  <p>But this does not work. I would like to be able to get the name and the score so that I can then insert them into a new collection that will also hold the score.</p>
  
  <p>I can get the name easily by:</p>
  
  <pre><code>while (cursor.hasNext()) 
  {
  DBObject next = cursor.next();
  String name = next.get("name").toString();
  }
  </code></pre>
  
  <p>But how do I get the score?</p>