dehaze

Paginate query results

The operators limit and skip are used for pagination.

limit specifies the number of rows to retain from the result set and skip determines the number of objects to skip (i.e. the offset of the result)

The following are examples of different pagination scenarios:

Limit resultslink

Example: Fetch the first 5 trainers from the list of all trainers:

query {
  trainers(
    limit: 5
  ) @mongo {
    _id
    name
  }
}
const { status, data } = await db.get("trainers")
  .limit(5)
  .apply()

Default limitlink

By default, if you don’t specify a limit clause in your query, Space Cloud enforces a limit of 1000 rows.

This default limit value can be configured easily in the database config. Head over to the Settings tab in the Database section of the Mission Control and scroll to the Default limit clause section. Change the value for the default limit and hit Save.

Skip and limit resultslink

Example: Fetch 5 trainers from the list of all trainers starting from the 6th one:

query {
  trainers(
    skip: 5,
    limit: 5
  ) @mongo {
    _id
    name
  }
}
const { status, data } = await db.get("trainers")
  .skip(5)
  .limit(5)
  .apply()

Skip and limit results on nested querieslink

Example: Fetch first 3 trainers and 2 pokemons of each trainer starting from the 6th one:

query {
  trainers(
    limit: 3
  ) @mongo {
    _id
    name
    pokemons(
      skip: 5,
      limit: 2
    ) @mongo {
      name
    } 
  }
}

Have a technical question?

Improve the docs!