title: Ordering MongoDB query results in less rows returned
body: <p>I'm having an issue with ordering in Mongoid (2.0.0.beta.17 and 2.0.2)/MongoDB. Perhaps I'm just not experienced enough with MongoDB, and some of you can help me understand what I'm doing wrong? </p>
  
  <p>The user-level symptoms are: </p>
  
  <ul>
  <li>Queries not sorting correctly by date or ID </li>
  <li>User posts are not appearing when they seem like they should be (this is a Twitter-like <a href="http://www.plantworking.com" rel="nofollow">social networking site for gardeners</a>, and the most recent posts are sometimes not showing up) </li>
  </ul>
  
  <hr>
  
  <pre><code>irb(main):024:0&gt; Update.all.size 
  </code></pre>
  
  <p>=> <strong>551</strong> </p>
  
  <pre><code>Update.ordered.size     # (see below for definition) 
  </code></pre>
  
  <p>=> <strong>490</strong> </p>
  
  <pre><code>irb(main):010:0&gt; Update.all.select{|u| u.created_at.nil?} 
  </code></pre>
  
  <p>=> [] </p>
  
  <p>When I go into the mongo shell, and do: </p>
  
  <pre><code>var cursor = db.updates.find({}, {'_id': 1}).limit(600); 
  while (cursor.hasNext()) printjson(cursor.next()); 
  </code></pre>
  
  <p>I get <strong>454</strong> lines returned. </p>
  
  <pre><code>var cursor = db.updates.find({}, {'_id': 1}).sort({created_at : 1}).limit(600); 
  while (cursor.hasNext()) printjson(cursor.next());   
  </code></pre>
  
  <p>Also returns <strong>454</strong> lines. </p>
  
  <pre><code>db.updates.find({}).sort({created_at: -1}).limit(1); 
  </code></pre>
  
  <p>returns an update from February 23rd. But I have updates from yesterday in MongoDB. 
  Any ideas? </p>
  
  <hr>
  
  <p>My model is: </p>
  
  <pre><code>class Update 
    include Mongoid::Document 
    include Mongoid::Timestamps 
    include Paperclip 
    field :body 
    ... 
    index [[ :created_at, Mongo::DESCENDING ]] 
    ... 
    named_scope :ordered, :order_by =&gt; ([[:created_at, :desc]]) 
    ... 
  end 
  </code></pre>