Class
FindCursor
A lazy, batched cursor over the results of a find.
Nothing is sent until the first read. Documents arrive in batches, and the
cursor releases its server-side state when it is exhausted or closed.
toArray() and for await close the cursor for you, even when the loop
exits early or throws.
class FindCursor<TDocument extends object = Document, TResult extends object = WithId<TDocument>> implements AsyncIterable<TResult>Defined in packages/driver/src/cursor.ts:143
Constructors#
constructor
#new FindCursor<TDocument extends object = Document, TResult extends object = WithId<TDocument>>(
execute: CursorExecutor,
collection: string,
filter: Document,
batchSize: number | undefined,
query?: FindQueryOptions,
)Defined in packages/driver/src/cursor.ts:149
Methods#
[asyncIterator]
#[asyncIterator](): AsyncGenerator<TResult, void, undefined>Iterates the remaining documents, closing the cursor when the loop ends.
Defined in packages/driver/src/cursor.ts:232
close
#close(): Promise<void>Closes the cursor and releases it on the server. Closing twice does nothing.
Defined in packages/driver/src/cursor.ts:225
explain
#explain(): Promise<ExplainResult>Asks the server how it would run this query, without running it. The sort, skip, limit, and batch size do not change the plan.
Defined in packages/driver/src/cursor.ts:189
hasNext
#hasNext(): Promise<boolean>Whether another document is available. This may fetch the next batch.
Defined in packages/driver/src/cursor.ts:201
next
#next(): Promise<TResult | null>Returns the next document, or null when the results are exhausted or
the cursor is closed.
Defined in packages/driver/src/cursor.ts:209
toArray
#toArray(): Promise<TResult[]>Reads all remaining documents into an array and closes the cursor. Large result sets are held in memory; iterate instead when they may be large.
Defined in packages/driver/src/cursor.ts:217