我遇到了在Mongoid(2.0.0.beta.17和2.0.2)/ MongoDB中排序的问题。也许我对MongoDB的体验不够,并且你们中的一些人可以帮助我理解我做错了什么?排序MongoDB查询结果返回的行较少
用户级的症状是:
- 查询不按日期或ID
- 用户讯息显示不正确排序时它们看起来他们应该是(这是一个类似Twitter social networking site for gardeners,和在最近发表的文章有时不显示)
irb(main):024:0> Update.all.size
=>
Update.ordered.size # (see below for definition)
=>
irb(main):010:0> Update.all.select{|u| u.created_at.nil?}
=> []
当我进入蒙戈壳,然后执行:
var cursor = db.updates.find({}, {'_id': 1}).limit(600);
while (cursor.hasNext()) printjson(cursor.next());
我得到线返回。
var cursor = db.updates.find({}, {'_id': 1}).sort({created_at : 1}).limit(600);
while (cursor.hasNext()) printjson(cursor.next());
也返回线。
db.updates.find({}).sort({created_at: -1}).limit(1);
从2月23日起返回更新。但是我有来自MongoDB的昨天更新。 任何想法?
我的模式是:
class Update
include Mongoid::Document
include Mongoid::Timestamps
include Paperclip
field :body
...
index [[ :created_at, Mongo::DESCENDING ]]
...
named_scope :ordered, :order_by => ([[:created_at, :desc]])
...
end
它们都是相同的时间类的实例化。其中454人。谢谢你的建议! – Jade 2011-05-26 15:01:10