Possible Duplicate:
How would I grab only articles with comments that were created 20 minutes ago?
Using mongodb and mongoid. How would one grab all articles and order by number of comments?
class Article
include Mongoid::Document
has_many :comments
end
class Comment
include Mongoid::Document
belongs_to :article
end
I wasn’t sure on the direction you were intending to sort in, so I included indexes for both – you should delete one, if you’re not planning to use it, but this should do the trick for you: