Skip to content

Find API

Query warnings

Some v4 query patterns ($exists, $ne, $nin, $not, unanchored or case-insensitive $regex) are slow on large components and return a warning header. They keep working. See v4 query warnings.

The Find API is the standard way to query and paginate through component model data. It returns a page of records along with total count metadata, and optionally resolves relation fields to their referenced documents.


When to use Find vs. other endpoints

Use case Recommendation
Paginated UI — fetching a page of results Find API (this page)
Processing all records — exports, migrations find(..., { stream: true })
Complex aggregations — grouping, facets Aggregation endpoint
Relation data exceeds 5 MB find(..., { stream: true })

Usage (SDK)

const result = await platform.component('orders').find({
    currentPage: 1,
    perPage: 25,
    sortBy: 'created_at',
    sortDesc: -1,
    filter: 'paid',
    filterOn: ['status'],
})

console.log(result.total)        // total matching records
console.log(result.total_pages)  // total pages
console.log(result.items)        // records on this page

With an advanced filter (MongoDB query)

const result = await platform.component('orders').find(
    { currentPage: 1, perPage: 25 },
    {
        $adv: { status: 'paid', amount: { $gte: 100 } },
    }
)

With a custom sort pipeline

const result = await platform.component('orders').find(
    { currentPage: 1, perPage: 25 },
    {
        $aggregate: [{ $sort: { 'amount': -1 } }],
    }
)

HTTP API

GET /{version}/system/component/{ref}/models

All parameters are passed as URL query string values.

Query parameters

Parameter Type Default Description
offset integer 1 Page number (1-based)
limit integer 250 Records per page. Clamped to 250 if 0 or greater than 250
sortBy string updated_at Field to sort by. Must be a sortable field — see sorting
sortDesc integer -1 Sort direction: -1 descending, 1 ascending. See sorting for the default when sortBy is supplied
filter string — Full-text search term applied across filterable fields
filterOn string — Comma-separated list of fields to restrict the text search to
dateFrom string (ISO 8601) — Lower bound for date range filter
dateTo string (ISO 8601) — Upper bound for date range filter
dateField string — Field to apply the date range filter against. Required when dateFrom or dateTo is sent
cursor string — Opaque cursor token for cursor-based pagination. See cursor pagination
$adv JSON string — Raw MongoDB query filter (serialised JSON object). In v4, some operators return a warning header: see v4 query warnings
$aggregate JSON string — Custom aggregation pipeline stages (JSON array). See pipeline rules
disabled boolean false When true, includes soft-deleted records

Response

{
    "items": [ /* array of model records */ ],
    "total": 1234,
    "total_filtered": 1234,
    "total_pages": 50,
    "page": 1
}
Field Description
items Records on the requested page. Each record has uuid, its field values at the top level (there is no data wrapper), created_at, updated_at, and resolved relation fields
total Total matching records (capped at 5 000, see limits)
total_filtered Same as total when a filter is active
total_pages Total number of pages (capped to reflect the 5 000-record limit)
page The current page number
next_cursor Opaque cursor token for the next page. Empty or absent on the last page. See cursor pagination

Pipeline validation

Pipelines supplied via $aggregate are validated before execution.

Allowed stages

Stage Description
$match Filter documents
$sort Sort documents
$project Shape output documents
$addFields / $set Add or overwrite computed fields
$unset Remove fields
$limit Limit result count
$skip Skip documents (maximum value: 5 000)
$group Group and aggregate
$facet Multi-faceted aggregation
$unwind Deconstruct arrays
$count Count documents

Forbidden stages

Stage Reason
$lookup Expensive cross-collection joins are handled internally by the relation resolver
$out / $merge Write operations are not permitted in query pipelines
$sample Random sampling can be slow on large collections
Any other stage Not on the allow-list

Pipeline length

A pipeline may contain at most 10 stages. Requests with longer pipelines are rejected.


Limits

Limit Value
Maximum records per page (limit) 250
Maximum records accessible (skip + limit) 5 000
Maximum pages shown Derived from 5 000 ÷ limit
Maximum total reported Capped at 5 000 even if more records exist
Relation data per page 5 MB
Pipeline stages 10
$skip value in user pipeline 5 000
Operation timeout 15 seconds

5 000-record cap

The Find API is designed for paginated UIs. If you need to access more than 5 000 records, use the streaming endpoint which supports up to 25 000 records with no relation-data cap per record.


Error responses

HTTP status Condition
400 Bad Request Invalid filter, disallowed pipeline stage, page beyond the 5 000-record limit, pipeline too complex
400 Bad Request Relation data for the page exceeds 5 MB — switch to the streaming endpoint
408 Request Timeout Operation did not complete within 15 seconds

Common error messages

pipeline too complex: has N stages, maximum allowed is 10
disallowed pipeline stage: $lookup
maximum allowed page is N (limited to 5000 records)
requested records exceed maximum limit of 5000
$skip value too high: N (maximum 5000)
relation data exceeds 5 MB limit; use the streaming endpoint

Sorting

sortBy names the field to order by and sortDesc the direction. Both are optional.

value
sortBy omitted updated_at, descending — newest first
sortBy supplied, sortDesc omitted ascending
sortDesc -1 descending, 1 ascending

Every sort is tie-broken by uuid in the same direction, so records with equal sort values have a stable order. This is what makes cursor pagination reliable.

Which fields can be sorted

A field can be sorted on when it stores a single scalar value — text, a number, a boolean or a date.

Field Stores
input:text, text:default, text:editor string
input:email, input:image, input:file string
select:text, select:image, select:relation string
radio:text string
picker:date, picker:datetime, picker:time, input:date date
input:number, select:number, radio:number number
checkbox:bool boolean
Field Stores Why
checkbox:text, checkbox:number array no single value to order by
table:default, table:custom array no single value to order by
image:carousel array no single value to order by
fieldset:default object no single value to order by
picker:daterange object sort by a scalar field instead
input:text_i18n, text:editor_i18n object one value per locale
data:json any shape is not known ahead of time
select:external any shape is not known ahead of time
input:password string hashed, and never returned

These system fields can also be sorted on: updated_at, created_at, uuid.

Anything else is rejected with a 400:

{ "error": "field \"tags\" (checkbox:text) is not sortable: it stores array" }

A field name that does not exist is rejected the same way. Previously a typo was accepted and every record sorted as equal, producing an arbitrary order — and cursor pagination on top of that returned unpredictable pages.

Sorting by an extension field

Use the full namespaced path, exactly as you would for reading or filtering:

GET /v4/system/component/orders/models?sortBy=extensions.shipping_tracker.carrier

The same rule applies — carrier is an input:text, so it sorts. An extension field that stores an array or object does not. See extensions.

Sorting by something not on the list

$aggregate is the escape hatch. A caller-supplied pipeline can $sort by anything, including a path into a data:json field:

[{ "$sort": { "context.data.client.last_name": 1 } }]

Aggregate sorts are not free

Nothing validates the shape, and nothing indexes it for you. An unindexed sort over a large collection is slow, scans the whole collection, and both the time and the bytes returned are billed. sortBy exists to keep the common path fast and predictable; $aggregate trades that away deliberately.


Cursor pagination

Offset-based pagination (offset / limit) works well for small datasets but degrades on large collections — the database must scan and skip all preceding records on every page request.

Cursor pagination eliminates this cost. Instead of a page number the client passes an opaque cursor token that tells the server exactly where to resume, using an indexed range query.

How it works

  1. First request — send a normal query without cursor. The response includes a next_cursor field.
  2. Subsequent requests — pass the next_cursor value from the previous response as the cursor parameter. The server seeks directly to the correct position.
  3. Last page — when fewer records than limit are returned, next_cursor is absent or empty. There are no more pages.

SDK example

// Page 1
const page1 = await platform.component('orders').find({
    currentPage: 1,
    perPage: 25,
    sortBy: 'updated_at',
    sortDesc: -1,
})

console.log(page1.items)        // first 25 records
console.log(page1.next_cursor)  // "eyJ2Ijoi..."

// Page 2 — pass the cursor
const page2 = await platform.component('orders').find({
    currentPage: 2,
    perPage: 25,
    sortBy: 'updated_at',
    sortDesc: -1,
    cursor: page1.next_cursor,
})

HTTP API example

Page 1:

POST /v4/system/component/{ref}/models
Content-Type: application/json
{ "offset": 1, "limit": 25, "sortBy": "updated_at", "sortDesc": -1 }

Response:

{
    "items": [ ... ],
    "total": 12000,
    "total_filtered": 12000,
    "total_pages": 480,
    "page": 1,
    "next_cursor": "eyJ2IjoiMjAyNi0wNi0yMlQwOToxMjowMFoiLCJpZCI6ImFiYy0xMjAifQ"
}

Page 2 — pass the cursor from the previous response:

POST /v4/system/component/{ref}/models
Content-Type: application/json
{ "offset": 2, "limit": 25, "sortBy": "updated_at", "sortDesc": -1, "cursor": "eyJ2IjoiMjAyNi0wNi0yMlQwOToxMjowMFoiLCJpZCI6ImFiYy0xMjAifQ" }

Important notes

Note Detail
Cursor + offset coexist When cursor is present the server uses it for seeking and ignores offset for skip calculation. offset is still used to report the page number in the response
Sort consistency The sortBy and sortDesc values must stay the same across pages — a cursor encodes the last seen sort value
Filter consistency Changing filters (search, $adv, date range) between pages invalidates the cursor. Start from page 1 when filters change
Cursor is opaque Do not parse or construct cursor tokens — treat them as strings. The internal format may change between versions

When to use cursor pagination

Use cursor pagination when you expect more than a few hundred records and users will navigate beyond page 20. For small datasets or the first few pages, offset-based pagination performs equally well.


FAQ

Can I sort by a relation field? Yes. Use $sort in the $aggregate pipeline targeting the internal _RefObj suffix field that the server embeds for relation fields (e.g., { $sort: { 'owner_RefObj.name': 1 } }).

Why is my total capped at 5 000? The Find API enforces a 5 000-record ceiling on offset-based pagination to protect query performance in a multi-tenant environment. Use the streaming endpoint for bulk access.

The relation data size error appears even with a small page size. Why? Each record on the page may reference many documents in another collection. The 5 MB budget accounts for the total raw BSON size of all resolved relation data for the page — not just the number of records. Reduce perPage or switch to the streaming endpoint.