Answer the question
In order to leave comments, you need to log in
How to properly implement pagination in MongoDB with sorting by compound index?
The question has a more abstract and theoretical character, even more likely not a question, but a reasoning on the topic.
skip()
and ranged queries , but by the will of fate they are mutually exclusive: skip()
// skip()
db.users
.find({
make: 'Mercedes-Benz',
model: 'S 500/550'
state: 'sale',
arr: { $in: [ 'used', 'notDamaged' ] }
mileage: { $lte: 80000 }
})
.sort({ priority: 1, age: -1, price: 1 })
.skip(200) // уже показанные результаты
.limit(25);
// Ranged query
db.users
.find({
_id: { $gt: lastId }, // _id последнего документа в последнем результате
make: 'Mercedes-Benz',
model: 'S 500/550'
state: 'sale',
arr: { $in: [ 'used', 'notDamaged' ] }
mileage: { $lte: 80000 }
})
.sort({ priority: 1, age: -1, price: 1 })
.limit(25);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question