Skip to main content

FindCursor

FindCursor class is an internal class that can be used to iterate over results from current collection.

Methods

sort

Set the sort order of the cursor query.

Type

type SortDirection = 1 | -1

type Sort<T> = Partial<{
[key in keyof T]: SortDirection
}>

class FindCursor<TSchema = any> {
sort(value: Sort<WithId<TSchema>>): this
}

skip

Set the skip for the cursor.

Type

class FindCursor<TSchema = any> {
skip(value: number): this
}

limit

Set the limit for the cursor.

Type

class FindCursor<TSchema = any> {
limit(value: number): this
}

toArray

Return an array of documents. Note that the array only contains partial results when this cursor had been previously accessed.

Type

type WithId<T> = T & {
_id: string
}

class FindCursor<TSchema = any> {
toArray(): Promise<WithId<TSchema>[]>
}

Example

async function find() {
const result = await myCollection
.find({
createdAt: {
$gt: 1668149554498
}
})
.sort({
createdAt: -1
})
.skip(0)
.limit(5)
.toArray()
console.log(result)
}