title: How to retrieve data from mongodb using scala
body: <p>I have connected to mongodb and filter data like this:</p>
  
  <pre><code>val coll = mongoDB.getTable(db, "report")
  val query = new BasicDBObject()
  query.put("version",getVersion)  
  val fields = new BasicDBObject()
  fields.put("version",1)
  fields.put("project",1)
  fields.put("uri",1)
  fields.put("test",1)
  fields.put("browser",1)
  val cursor = coll.find(queryObject,fields)
  </code></pre>
  
  <p>then get a document like this:</p>
  
  <pre><code>{
    "_id" : ObjectId("5a968c6cffac6135b09d6cd5"),
    "project" : "com.sink.www.helper",
    "uri" : "com.sink.www.helper.somketest",
    "browser" : "firefox",
    "develop" : "scala",
    "duration" : "0.61",
    "test" : "acceptance"
    "version" : "1.0"
     "try" : 1
  }
  
  {
    "_id" : ObjectId("5a968daaffacc7195c2f9b6i"),
    "project" : "com.sink.www.helper",
    "uri" : "com.sink.www.helper.somketest",
    "browser" : "firefox",
    "develop" : "scala",
    "duration" : "0.62",
    "test" : "acceptance"
    "version" : "1.0"
    "try" : 1
  }
  
  {
    "_id" : ObjectId("5a968ea5fface1a723ffr246"),
    "project" : "com.sink.www.helper",
    "uri" : "com.sink.www.helper.somketest",
    "browser" : "chrome",
    "develop" : "scala",
    "duration" : "0.58",
    "test" : "acceptance"
    "version" : "1.0"
    "try" : 1
  }
  </code></pre>
  
  <p>.....</p>
  
  <p>My question is when "version" is specific value like '1.0', then the field try=try + 1,  I have write code like this but this will read mongodb every time, this will cost much time:</p>
  
  <pre><code>while (cursor.hasNext())
  {
      val details = cursor.next()
      if (details.get("version").toString() == getVersion &amp;&amp; details.get("browser").toString() == getBrowser)
        {
           try += 1
        }
  }
  </code></pre>
  
  <p>because there are much data in mongodb, so it's not adapt to our project. so I want to get specific data to array or others and get to judge then let try+1, I write code like this but report error:</p>
  
  <pre><code>val scenarioArray = coll.find(queryObject,fields).toArray
  for (i &lt;- 0 to scenarioArray.length - 1)
   {
     println(scenarioArray(i))
   }
  </code></pre>
  
  <p>error: value length is not a member of java.util.List[com.mongodb.DBObject]
  error: java.util.List[com.mongodb.DBObject] does not take parameters
  I don't know how to retrieve the document to array or list or others container, could anyone get to help on this? Thanks.</p>