Skip to Content
DocsConceptsQuery model

Query model

find takes where, sort, limit, page or cursor, select and depth. The same model works on every adapter.

const result = await qb.find( "posts", { where: { or: [{ status: { eq: "draft" } }, { views: { gte: 10 } }] }, sort: ["-publishedAt", "title"], limit: 20, page: 2, select: ["title", "status"], depth: 1, }, { user }, );

Operators

OperatorFieldsMatches null?
eq, insingle-value fields except jsonno
ne, notInsingle-value fields except jsonyes
lt, lte, gt, gtetext, number, date, datetime, timestampsno
contains, startsWithtext-like fields, case-insensitiveno
existsall fieldsexists: false does

On many fields the operators mean:

OperatorMatches when the array
containshas the value
inhas any of the values
notInhas none of the values
existsis not empty (true) or empty (false)

Combining filters

FormMeaning
Keys in one objectAND
and: [a, b]AND. and: [] matches all.
or: [a, b]OR. or: [] matches nothing.
const where = { status: { eq: "published" }, or: [{ title: { contains: "release" } }, { tags: { contains: "tag-id" } }], } as const; await qb.find("posts", { where }, { user });

Sorting

RuleDetail
Syntax"field" ascending, "-field" descending, or an array.
Default-createdAt
Tie-breakCore appends id in the direction of the last key.
NullsLast when ascending, first when descending.
Not sortablemany fields and json fields.

Pagination

ModeUseReturns
Pagelimit + page (default limit 20)totalDocs, totalPages, page, hasNextPage, nextCursor
Cursorlimit + cursorhasNextPage, nextCursor. page, totalDocs, totalPages are null.
const first = await qb.find("posts", { sort: "-createdAt", limit: 50 }, { user }); if (first.nextCursor) { const second = await qb.find( "posts", { sort: "-createdAt", limit: 50, cursor: first.nextCursor }, { user }, ); }

A cursor only works with the sort it was made for. Do not combine page and cursor. Cursor mode skips the count query.

Select and depth

OptionValuesEffect
selectfield namesReturn only these fields and id.
depth0–3Load related documents. One query per related collection and level. Default 0.

Invalid filters, sort keys, select keys or cursors throw ValidationError.

Last updated on