title: How to batch retrieve documents with mongoDB?
body: <p>I have an application that queries data from a mongoDB using the mongoDB C# driver something like this: </p>
  
  <pre><code>public void main()  
  {
     foreach (int i in listOfKey)
     {
        list.add(getObjectfromDB(i);
     } 
  }
  
  public myObject getObjFromDb(int primaryKey)
  {
     document query = new document();
     query["primKey"] = primaryKey;
     document result= mongo["myDatabase"]["myCollection"].findOne(query);
     return parseObject(result);
  }
  </code></pre>
  
  <p>On my local (development) machine to get 100 object this way takes less than a second. However, I recently moved the database to a server on the internet, and this query takes about 30 seconds to execute for the same number of object. </p>
  
  <p>Furthermore, looking at the mongoDB log, it seems to open about 8-10 connections to the DB to perform this query. </p>
  
  <p>So what I'd like to do is have the query the database for an array of primaryKeys and get them all back at once, then do the parsing in a loop afterwards, using one connection if possible.</p>
  
  <p>How could I optimize my query to do so?<br>
  Thanks,<br>
  --Michael  </p>