MongoDB sorting

Sorting in MongoDB is done like so:

db.collection.find({ ... spec ... }).sort({ key: 1 })

where 1 is ascending and -1 is descending.

In your specific example: db.topics.find().sort({ bump_date: 1 }), although it might be better to call it something like “updated_at”.

You’ll also definitely want to put an index on your “bump_date” field.

  • sorting: http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order
  • indexes: http://www.mongodb.org/display/DOCS/Indexes

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)