title: MongoDB Select with QueryBuilder
body: <p>i'm trying to select values from my database, but currently i'm unable to to it and although i know its the fact that the method doesnt except the QueryBuilder class as  a parameter, i dont know what to do about it. I only found solutions for querys with one parameter or all parameters are not null. In my case i've a List with ID, and 4 parameters which dont have to be passed to the function so they could be null.</p>
  
  <p>My current code looks like this.</p>
  
  <pre><code>collection = db.GetCollection&lt;Datapoint&gt;("test");
  
  var query = new QueryBuilder&lt;Datapoint&gt;();
  var queryattributes = new List&lt;IMongoQuery&gt;();
  var ids = new List&lt;IMongoQuery&gt;();
  
  // Add all Attributes if there
  if (fromdate != null)
  {
       BsonDateTime from = BsonDateTime.Create(fromdate);
       queryattributes.Add(Query.GTE("UTCTimestamp", from));
  }
  if (to != null)
  {
      BsonDateTime bto = BsonDateTime.Create(to);
      queryattributes.Add(Query.LTE("UTCTimestamp", bto));
  }
  if (evId != null)
  {
      queryattributes.Add(Query.EQ("EvId", evId));
  }
  if (evType != null)
  {
      queryattributes.Add(Query.EQ("EvType", evType));
  }
  
  // Add all ID's
  Parallel.ForEach(idList, data =&gt;
  {
      lock (query)
      {
          ids.Add(Query.EQ("CId", data));
      }
  });
  
  // But everything in the Query
  query.Or(ids);
  
  // Add Queryattributes if there
  if (queryattributes.Count &gt; 0)
  {
      query.And(queryattributes);
  }
  
  var result = collection.FindAs&lt;Datapoint&gt;(query);
  </code></pre>
  
  <p>I'm trying to do it without Linq, since i found countless of test, which say that linq is much much slower, and since i want to run it as an Databasetest, i kinda need the performace to execute alot of querys.</p>
  
  <p>The Linq query looks like this</p>
  
  <pre><code>var query2 =
      from e in collection.AsQueryable&lt;Datapoint&gt;()
      where idList.Contains(e.CId)
          &amp;&amp; (evtId == null || e.EvId == evId)
          &amp;&amp; (evType == null || e.EvType == evType.Value)
          &amp;&amp; (fromdate == null || Query.GTE("UtcTimestamp", BsonDateTime.Create(fromdate)).Inject())
          &amp;&amp; (to == null || Query.LT("UtcTimestamp", BsonDateTime.Create(to)).Inject())
      select e;
  </code></pre>