S
S
Stanislav2017-01-05 14:23:56
MongoDB
Stanislav, 2017-01-05 14:23:56

Smart sorting on two fields?

It is necessary to sort the records when selecting by the date of its update and by moderation.
The actual documents of such a plan

{
    public: true, // true - опубликована, false - закрыта
    updatedAt: Data.now // дата последнего изменения документа
}

I would like to achieve such a result in which closed records will occupy the last places in the selection even if they were recently updated, and those records that were approved and recently updated were at the very beginning.
Only with the help of aggregate can you realize your plans? Or is there some other sorting method?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-01-05
@ms-dred

.sort({public: 1, updatedAt: 1})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question