findServer
Find documents in a collection with optional pagination and total count.
When includeTotalCount=true, runs .collect() on the first page to count all
matching documents. Returns null if count exceeds 32k documents.
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 count (first page only)const result = await find({ ctx, collection: "posts", paginationOpts: { numItems: 100, cursor: null }, includeTotalCount: true,});// result: { page: [...], continueCursor: "...", isDone: false, totalCount: 1523 }Call Signature
Section titled “Call Signature”findServer<
DataModel,TCollectionSlug,TPopulate,D>(args):Promise<DocReturnItem<TCollectionSlug,TPopulate,D>[]>
Defined in: packages/core/src/api/find/server.ts:131
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/api/find/server.ts:145
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>>>