Answer the question
In order to leave comments, you need to log in
How to make a request in Mongoose?
You need to take the last 50 records from the collection and group them by field.
Answer the question
In order to leave comments, you need to log in
there is little information about the structure of the collection, but in general - the so-called aggregation pipeline
did this with its local database of Deals offers, grouped by city
Deal.aggregate([
{
'$sort': {
'_id': -1 // тупо по айди, если есть поле в духе created_at, то использовать его
}
}, {
'$limit': 50
}, {
'$group': {
'_id': '$city', // сюда поле
'data': {
'$push': '$$ROOT' // это чтобы добавился массив с записями в результат
}
}
}
])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question