Haina
Haina

Reputation: 55

How to use order by desc in mongomodel for rails3

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

Answers (6)

araslanov_e
araslanov_e

Reputation: 309

Now you can @article = Article.where().desc(:title)

Upvotes: 1

harsh4u
harsh4u

Reputation: 2600

Use below:

@article = Article.where(..your condition..).order_by(:title => "desc")

Upvotes: 3

Steffen
Steffen

Reputation: 41

This should work:

 @article = Article.where().order("title desc")

Upvotes: 4

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

SteffanPerry
SteffanPerry

Reputation: 1

@articles = Article.where(:order => title.desc)

Upvotes: 0

Sam Pohlenz
Sam Pohlenz

Reputation: 1

Try:

@articles = Article.where(...).order(:title.desc)

Upvotes: -1

Related Questions