1

I am attempting to implement pagination using MongoDB Stitch in Swift for iOS, but I do not see skip in the docs.

The RemoteFindOptions has sort and limit but no skip like so:

{
   "projection": <document>,
   "sort": <document>,
   "limit": <integer>
}

Is there no way to implement skip with mongodb stitch for iOS?

Koh
  • 2,687
  • 1
  • 22
  • 62

2 Answers2

0

Is there no way to implement skip with mongodb stitch for iOS?

For pagination, you could create a Stitch Function that returns a limited number of result using limit.

Essentially performing an operation similar to below:

db.collection.find({ "_id": 100 })
    .sort({ _id: 1 })
    .limit(50)

The example snippet above shows an example pagination of 50. On the client side, make sure to record the last _id, so that you can perform another pagination request. i.e.

db.collection.find({ "_id": 150 })
    .sort({ _id: 1 })
    .limit(50)

See also:

Wan B.
  • 18,367
  • 4
  • 54
  • 71
0

You can use aggregate instead of find. For example:

myCollection.aggregate([
    { $sort: { createdAt: -1 } },
    { $skip: 10 },
    { $limit: 10 }
]).toArray()
René
  • 2,912
  • 1
  • 28
  • 46