title: Dynamically build query for Azure DocumentDB
body: <p>I recently swichted from MongoDB to Azure DocumentDB and want check if a duplicate document exists in the collection by dynamically building a query.</p>
  
  <p>This is how I solved the query building with MongoDB:</p>
  
  <pre><code>MongoCollection collection = mongoDbDatabase.GetCollection&lt;BsonDocument&gt;("123");
  var clauses = new List&lt;IMongoQuery&gt;();
  
  foreach (var currResult in Results)
  {
      //add query
      clauses.Add(Query.EQ("_result", currResult));
      clauses.Add(Query.EQ("_id", myId));
  }
  
  var query = (clauses.Count &gt; 0) ? Query.And(clauses) : null;
  
  if (query != null)
  {
      //check if we have at least one duplicate
      if (collection.FindOneAs&lt;BsonDocument&gt;(query) != null)
      {
          DoSomething();
      }
  }
  </code></pre>
  
  <p>Right now I am using LINQ to check for duplicates in DocumentDB:</p>
  
  <pre><code>var result = (from c in documentDb.CreateDocumentQuery&lt;Results&gt;(collection.SelfLink)
                where c.result = currResult &amp;&amp;
                c.id == myId
                select c).AsEnumerable();
  int numResults = result.Count();
  if(numResults &gt; 0)
  {
      DoSomething();
  }
  </code></pre>
  
  <p>How can I dynamically build the where clause like <code>Query.And(clauses)</code> using DocumentDB?</p>
  
  <p>Thanks</p>