0 votes
1 view
in SQL by (47.7k points)

I can't find anywhere it has been documented this. By default, the find() operation will get the records from the beginning. How can I get the last N records in MongoDB?

1 Answer

0 votes
by (107k points)

From your question it looks like, you want to sort in ascending order:-

For that, you can use sort() function:-


If you pass the 1 as a parameter then it will sort in ascending order and if you pass -1 then it will sort in descending order.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !