title: mongoid/ mongodb query with time condition is extremely slow
body: <p>I want to select all the data which ts(<strong>timestamp</strong>) less than <strong>specific time</strong></p>
  
  <pre><code>last_record = History.where(report_type: /#{params["report_type"]}/).order_by(ts: 1).only(:ts).last
  History.where(:ts.lte =&gt; last_record.ts)
  </code></pre>
  
  <p>It seems this query will take super long time</p>
  
  <p>I don't understand why, is there any quick way to do the sort of query ?</p>
  
  <pre><code>class History
    include Mongoid::Document
    include Mongoid::Timestamps
    include Mongoid::Attributes::Dynamic
    field :report_type, type: String
    field :symbol, type: String
    field :ts, type: Time
  end
  </code></pre>
  
  <p><img src="https://i.imgur.com/pe0bhL9.png" alt=""></p>
  
  <h2>The query log in console</h2>
  
  <pre><code>Started GET "/q/com_disagg/last" for 127.0.0.1 at 2015-01-10 10:36:55 +0800
  Processing by QueryController#last as HTML
    Parameters: {"report_type"=&gt;"com_disagg"}
    MOPED: 127.0.0.1:27017 COMMAND      database=admin command={:ismaster=&gt;1} runtime: 0.4290ms
      ...  
    MOPED: 127.0.0.1:27017 GET_MORE     database=cot_development collection=histories limit=0 cursor_id=44966970901 runtime: 349.9560ms
  </code></pre>
  
  <h3>Have set the timestamp as index, but still extremely slow query</h3>
  
  <blockquote>
    <p>db.system.indexes.find()</p>
  </blockquote>
  
  <pre><code>{ "v" : 1, "key" : { "ts" : 1 }, 
  "name" : "ts_index",
   "ns" : "cot_development.histories" }
  </code></pre>