Reputation: 55
Hello I use rails3+mongomodel+mongodb.I can sort data by asc but I don't know how to order by desc
@article = Article.where().sort(['title'])
This code order by asc.if not use sort() data will select by create date.
How to order by desc
Upvotes: 1
Views: 2551
Reputation: 2600
Use below:
@article = Article.where(..your condition..).order_by(:title => "desc")
Upvotes: 3
Reputation: 116
I believe that something like this will work:
@articles = Article.order('title DESC')
When I do that I see the following query generated:
find({}, {}).sort([["title", :descending]])
So I assume it's using the mongo backend.
Upvotes: 2