Reputation: 324
I can see the limit option in mongoDB Stitch docs but unable to find how can we skip records for pagination.
Upvotes: 3
Views: 592
Reputation: 254
You can use aggregate with pipeline. Something like that:
exports = function(arg){
const mongodb = context.services.get("mongodb-atlas");
const coll = mongodb.db(<dbname>).collection(<collectionname>);
const pipeline = [
{ "$skip" : 1 },
{ "$limit": 20 }
];
return coll
.aggregate(pipeline)
.toArray();
};
Upvotes: 8
Reputation: 517
this will skip 1st 100 doc from the result
db.collection.find({query}).skip(100)
here query is what you queried for.
Upvotes: -2