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
Example
Section titled “Example”// Without paginationconst docs = await find({ ctx, collection: "posts" });
// With paginationconst result = await find({ ctx, collection: "posts", paginationOpts: { numItems: 100, cursor: null },});// result: { page: [...], continueCursor: "...", isDone: false }
// With pagination and a first-page countconst result = await find({ ctx, collection: "posts", paginationOpts: { numItems: 100, cursor: null, totalDocs: true },});// result: { page: [...], continueCursor: "...", isDone: false, totalDocs: 1523, totalDocsCapped: false }Call Signature
Section titled “Call Signature”findServer<
DataModel,TCollectionSlug,TPopulate,D>(args):Promise<DocReturnItem<TCollectionSlug,TPopulate,D>[]>
Defined in: packages/core/src/collections/api/find/server.ts:162
Type Parameters
Section titled “Type Parameters”DataModel
Section titled “DataModel”DataModel extends GenericDataModel
TCollectionSlug
Section titled “TCollectionSlug”TCollectionSlug extends string
TPopulate
Section titled “TPopulate”TPopulate extends PopulateShape<TCollectionSlug> = Record<string, never>
D extends number = 0
Parameters
Section titled “Parameters”FindServerArgs<DataModel, TCollectionSlug, TPopulate, D> & object
Returns
Section titled “Returns”Promise<DocReturnItem<TCollectionSlug, TPopulate, D>[]>
Call Signature
Section titled “Call Signature”findServer<
DataModel,TCollectionSlug,TPopulate,D>(args):Promise<PaginationResult<DocReturnItem<TCollectionSlug,TPopulate,D>>>
Defined in: packages/core/src/collections/api/find/server.ts:176
Type Parameters
Section titled “Type Parameters”DataModel
Section titled “DataModel”DataModel extends GenericDataModel
TCollectionSlug
Section titled “TCollectionSlug”TCollectionSlug extends string
TPopulate
Section titled “TPopulate”TPopulate extends PopulateShape<TCollectionSlug> = Record<string, never>
D extends number = 0
Parameters
Section titled “Parameters”FindServerArgs<DataModel, TCollectionSlug, TPopulate, D> & object
Returns
Section titled “Returns”Promise<PaginationResult<DocReturnItem<TCollectionSlug, TPopulate, D>>>