Skip to content

findServer

Find documents in a collection with optional pagination and total count.

Pass paginationOpts: { ..., totalDocs: true } to also count matching documents on the first page (cursor: null) only. Counts with take(countLimit + 1) instead of .collect()-ing the whole matching set (Design Decision 35, default countLimit 10000) — totalDocs is the exact count up to that cap, never null; totalDocsCapped: true means more matching documents exist beyond the cap and totalDocs equals countLimit, a floor rather than an exact count.

args

Find arguments including filters, sort, pagination, and count options

// Without pagination
const docs = await find({ ctx, collection: "posts" });
// With pagination
const result = await find({
ctx,
collection: "posts",
paginationOpts: { numItems: 100, cursor: null },
});
// result: { page: [...], continueCursor: "...", isDone: false }
// With pagination and a first-page count
const result = await find({
ctx,
collection: "posts",
paginationOpts: { numItems: 100, cursor: null, totalDocs: true },
});
// result: { page: [...], continueCursor: "...", isDone: false, totalDocs: 1523, totalDocsCapped: false }

findServer<DataModel, TCollectionSlug, TPopulate, D>(args): Promise<DocReturnItem<TCollectionSlug, TPopulate, D>[]>

Defined in: packages/core/src/collections/api/find/server.ts:162

DataModel extends GenericDataModel

TCollectionSlug extends string

TPopulate extends PopulateShape<TCollectionSlug> = Record<string, never>

D extends number = 0

FindServerArgs<DataModel, TCollectionSlug, TPopulate, D> & object

Promise<DocReturnItem<TCollectionSlug, TPopulate, D>[]>

findServer<DataModel, TCollectionSlug, TPopulate, D>(args): Promise<PaginationResult<DocReturnItem<TCollectionSlug, TPopulate, D>>>

Defined in: packages/core/src/collections/api/find/server.ts:176

DataModel extends GenericDataModel

TCollectionSlug extends string

TPopulate extends PopulateShape<TCollectionSlug> = Record<string, never>

D extends number = 0

FindServerArgs<DataModel, TCollectionSlug, TPopulate, D> & object

Promise<PaginationResult<DocReturnItem<TCollectionSlug, TPopulate, D>>>