title: Recursively Build MongoDBObject
body: <p>How can I recursively append to a <code>DBObject</code> in Casbah, and then return a single <code>MongoDBObject</code> with each list element appended? </p>
  
  <p>Note that the below does not compile or work, but it intends to show my desired code</p>
  
  <pre><code>def foo( pairs: List[(String, Int)]): List[MongoDBObject] = {
    def go( ps: List[(String, Int)], acc: List[MongoDBObject]): List[MongoDBObject] =
        ps match {
           case x :: xs if(x._1 == "BAD") =&gt; go(xs, acc)
           case x :: xs =&gt;  go(xs, MongoDBObject(x._1 -&gt; x._2) :+ acc) /* error line */
           case Nil =&gt; acc
    }
  }
  
  val pairsList: List[MongoDBObject] = foo( getPairs() ) // assume getPairs() is defined
  val builder = // do something to convert pairsList -&gt; MongoDBObject (maybe a fold?)
  val results = collection.find(builder) 
  </code></pre>
  
  <p>When I tried something like the above, I saw the following compile-time error at my second case statement.</p>
  
  <pre><code>[myApp] $ compile
  [info] Compiling 1 Scala source to ...
  [error] c:\development\myApp\Test.scala:85: overloaded method value apply with alternatives:
  [error]   [A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply) &lt;
  : String, B(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)](e
  lems: List[(A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply),
   B(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply))])com.mongo
  db.casbah.commons.Imports.DBObject &lt;and&gt;
  [error]   [A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply) &lt;
  : String, B(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)](e
  lems: (A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply), B(in
   method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply))*)com.mongodb.ca
  sbah.commons.Imports.DBObject
  [error]  cannot be applied to (com.mongodb.casbah.query.Imports.DBObject with com.mongodb.casbah.query.dsl.QueryExpressionObject)
  [error]   go(xs, acc :+ MongoDBObject(elemMatch))
  [error]                                                                               ^
  [error] one error found
  </code></pre>