I have to sort a mongodb collection in ruby via the mongodb driver.When I sort in the db directly using
db.zipper.find().sort({"value":-1})
But when I do the same thing in ruby,the collection is not getting sorted.I am using
coll = db.collection('zipper')
coll.find().sort({"value":-1})
Tell me where I am going wrong.I tried with
coll.find.sort(:value,:desc)
But that too is in vain.Tell me where I am going wrong.
You need to pass the sort options as an array of key value pairs, eg:
With the Ruby driver you can also use
descordescendingas semantic equivalents for the-1reverse sort order: