S
S
Stopy2015-04-13 22:52:15
MongoDB
Stopy, 2015-04-13 22:52:15

How to make such a query to the mongoDB database?

I have a database with many content records { text: 'message text', date: '*date the record was added*' }
The date field is formed like this date: new Date()
How to write a query that will display 10 records sorted by date , i.e. first recent, then old?
MongoDB, node.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Shatokhin, 2015-04-13
@Stopy

If using the Node.js MongoDB driver:

collection.find({}).sort({date: -1}).limit(10).toArray(function (data) { /* ваш код */ });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question