2017  Kodetalk | Feedback | Privacy Policy | Terms | About

How to sort a collection by date in MongoDB?

For example the collection USER have a key "CREATED_DATE" and want to display the complete collection by date like descending order.

What"s best way to do this:


To do this follow the process:

1: db.USER.find().sort("CREATED_DATE":-1);

this will give the complete collection in descending order.

Answer is