MongoDB paging
Paging a large collection in memory loads every document. MongoCollection.queryPage pushes the count, sort, skip, and limit into MongoDB and returns an Arc page with the real total.
@query(service(tasks), queryOptions())static async page(items: MongoCollection<TaskRecord>, options: QueryOptions) { return items.queryPage({}, options);}GET /api/.../page?page=0&pageSize=10&sortBy=title answers with ten documents sorted by title and paging.totalItems counted by MongoDB.
queryPage(filter, options)defaults to the firstmaxPageSizerows when paging is absent. Each read is capped atmaxPageSize, 100 by default and at most 10,000. If the count exceeds the cap, Arc rejects the incomplete unpaged result with 400 rather than returning partial data.- Only fields declared on the model may be sorted. The Arc wire name resolves to the declared property, then to its BSON name under the selected naming policy. An unknown field, including
$where, answers 400. - An
_idtie-breaker makes page order stable. An application-provided default sort is used when the request asks for none. - For an intentionally unbounded list, use
items.find(); do not use it on large collections.
Consistency
Section titled “Consistency”The count and the find are separate reads. A concurrent write can change the count between them; this is not a snapshot transaction.