title: How to build index for dynamic criteria in mongodb to improve performance
body: <p>I am building mongodb object and passing it to  findAll method of mongo repository. </p>
  
  <p>How can I achieve faster performance by designing index around all these fields ?</p>
  
  <pre><code>val criteriaQuery = MongoDBObject.newBuilder
  criteriaQuery += OrderNames.CLIENT_ID -&gt; clientId
  if (StringUtils.isNotBlank(orderId))
    criteriaQuery += OrderNames.ORDER_ID -&gt; orderId
  if (StringUtils.isNoneBlank(customerEmail))
    criteriaQuery += OrderNames.CUSTOMER_EMAIL -&gt; customerEmail
  if (orderStartDate != null) {
    if (orderEndDate != null)
      criteriaQuery += OrderNames.ORDER_DATE -&gt; MongoDBObject("$gte" -&gt; orderStartDate, "$lte" -&gt; orderEndDate)
    else
      criteriaQuery += OrderNames.ORDER_DATE -&gt; MongoDBObject("$gte" -&gt; orderStartDate)
  }
  else if(orderEndDate != null)
    criteriaQuery += OrderNames.ORDER_DATE -&gt; MongoDBObject("$lte" -&gt; orderEndDate)
  return criteriaQuery.result
  </code></pre>
  
  <p>My question here is : 
   if i have a, b, c, d, e, f in criteria.
   And if i create index on (a, b, c, d, e, f)</p>
  
  <p>Will it work for (a,c,d,e,f) , (a, c), (a, e, f), (a,c, f)) etc.
   I need to consider all of these ?</p>