In general, I encountered such a problem: when I receive docks, I need to sort them by _id in ascending order, and then take a certain number, starting either from the beginning of the array or from the end. That is, I need to get all the new docks (which have the most _id ), in the amount of 100 pieces, or, for example, the oldest in the same quantity, but the limiting does not take into account the sorting, and returns the last modified docks. Is it possible to somehow solve the problem using MongoDB , without resorting to manual filtering?
- 2SO: uses for mongodb ObjectId creation time items.find.sort ([['_id', -1]]) // get all items des created by date. items.find.sort ([['_id', -1]]) .limit (30) // get last 30 createad items - Yura Ivanov
- @Yura Ivanov, thank you, this example helped me to understand exactly what elements are taken when limiting) - Pifagorych
|