2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

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:

userimage

To do this follow the process:

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

this will give the complete collection in descending order.

Answer is