P
P
picka2021-04-04 23:04:22
Mongoose
picka, 2021-04-04 23:04:22

How to find top 10 records in MongoDB using mongoose?

There are entries like this:

[
  {
    name: 'статья',
    popularity: 12
  },
  {
    name: 'статья',
    popularity: 10
  },
  {
    name: 'статья',
    popularity: 15
  },
]


How to extract, for example, the 10 most popular entries from such a collection?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-04-05
@vabka

.

Records
.find(...)
.sort({popularity: -1})
.limit(10)
.exec(...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question