Muhammad Furqan
Muhammad Furqan

Reputation: 324

How can we skip records in mongodb stitch?

I can see the limit option in mongoDB Stitch docs but unable to find how can we skip records for pagination.

enter image description here

Upvotes: 3

Views: 592

Answers (2)

Aras Cglzn
Aras Cglzn

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

nishant kumar
nishant kumar

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

Related Questions