title: Slow querying inside a list of references in mongodb
body: <p>I'm saving a log of searches in the website in MongoDB via Morphia and using Play 2. The log has the usual query term and list of results. So basically like this:</p>
  
  <pre><code>public class SearchLog {
  
      public String query;
  
      @Indexed
      @Reference(lazy = true, ignoreMissing = true)
      public List&lt;Result&gt; results;
  
      @Indexed
      @Embedded
      public LocalDateTime timestamp;
  
  }
  </code></pre>
  
  <p>I build a query based on when the searches were done and whether the results contain "this" like so.</p>
  
  <pre><code>Query q = q().filter("timestamp &gt;=", start).filter("timestamp &lt;=", end)
      .field("results").hasThisElement(something).order("timestamp").asList();
  </code></pre>
  
  <p>There are about 8000 log entries in the database with each log containing ~10-20 Results. This particular query I'm testing returns about 4000 entries. However, the query is extremely slow (>10 sec) even with Index. Did I do anything wrong/is there a way to optimise how MongoDB do the query?</p>
  
  <p>Thanks</p>