Note that there are some explanatory texts on larger screens.

plurals
  1. POOrdering MongoDB query results in less rows returned
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload