Interface GenericFindOptions

Overview

The options for a generic find command performed on the Data API.

Example

const results = await collection.find({
category: 'electronics',
}, {
sort: { price: 1 },
limit: 10,
timeout: 10000,
});

Builder methods

You can also use fluent builder methods on the cursor:

Example

const cursor = collection.find({ category: 'electronics' })
.sort({ price: 1 })
.limit(10)
.skip(5);

const results = await cursor.toArray();

See

  • CollectionFindOptions
  • TableFindOptions
interface GenericFindOptions {
    includeSimilarity?: boolean;
    includeSortVector?: boolean;
    initialPageState?: null | string;
    limit?: number;
    maxTimeMS?: "ERROR: The `maxTimeMS` option is no longer available; the timeouts system has been overhauled, and timeouts should now be set using `timeout`";
    projection?: Projection;
    skip?: number;
    sort?: Sort;
    timeout?: number | Pick<Partial<TimeoutDescriptor>, "requestTimeoutMs" | "generalMethodTimeoutMs">;
    vector?: "ERROR: Use `sort: { $vector: [...] }` instead";
    vectorize?: "ERROR: Use `sort: { $vectorize: \"...\" }` instead";
}

Hierarchy (view full)

Properties

includeSimilarity?: boolean

If true, include the similarity score in the result via the $similarity field.

See FindCursor.includeSimilarity for more details and examples.

includeSortVector?: boolean

If true, the sort vector will be available through await cursor.getSortVector() and await cursor.fetchNextPage().

See FindCursor.getSortVector for more details and examples.

initialPageState?: null | string

Sets the starting page state for the cursor.

See FindCursor.initialPageState for more details and examples.

limit?: number

The maximum number of records to return in the lifetime of the cursor.

See FindCursor.limit for more details and examples.

maxTimeMS?: "ERROR: The `maxTimeMS` option is no longer available; the timeouts system has been overhauled, and timeouts should now be set using `timeout`"

This temporary error-ing property exists for migration convenience, and will be removed in a future version.

Deprecated

  • The maxTimeMS option is no longer available; the timeouts system has been overhauled, and timeouts should now be set using timeout, and defaults in timeoutDefaults. You may generally Ctrl+R replace maxTimeMS with timeout to retain the same behavior.
projection?: Projection

The projection to apply to the returned records, to specify only a select set of fields to return.

See FindCursor.project for more details and examples.

skip?: number

The number of records to skip before starting to return records.

See FindCursor.skip for more details and examples.

sort?: Sort

The order in which to apply the update if the filter selects multiple records.

See FindCursor.sort for more details and examples.

timeout?: number | Pick<Partial<TimeoutDescriptor>, "requestTimeoutMs" | "generalMethodTimeoutMs">
Overview

Lets you specify timeouts for individual methods, in two different formats:

  • A subtype of TimeoutDescriptor, which lets you specify the timeout for specific categories.
  • A number, which specifies the "happy path" timeout for the method.
    • In single-call methods, this sets both the request & overall method timeouts.
    • In multi-call methods, this sets the overall method timeout (request timeouts are kept as default).

Example

// Both `requestTimeoutMs` and `generalMethodTimeoutMs` are set to 1000ms.
await coll.insertOne({ ... }, { timeout: 1000 });

// `requestTimeoutMs` is left as default, `generalMethodTimeoutMs` is set to 2000ms.
await coll.insertOne({ ... }, { timeout: { generalMethodTimeoutMs: 2000 } });

// Both `requestTimeoutMs` and `generalMethodTimeoutMs` are set to 2000ms.
await coll.insertMany([...], {
timeout: { requestTimeoutMs: 2000, generalMethodTimeoutMs: 2000 },
});

Example

// `requestTimeoutMs` is left as default, `generalMethodTimeoutMs` is set to 2000ms.
await coll.insertMany([...], { timeout: 2000 });

// `requestTimeoutMs` is left as default, `generalMethodTimeoutMs` is set to 2000ms.
await coll.insertMany([...], { timeout: { generalMethodTimeoutMs: 2000 } });

// Both `requestTimeoutMs` and `generalMethodTimeoutMs` are set to 2000ms.
await coll.insertMany([...], {
timeout: { requestTimeoutMs: 2000, generalMethodTimeoutMs: 2000 },
});

See TimeoutDescriptor for much more information.

See

TimeoutDescriptor

vector?: "ERROR: Use `sort: { $vector: [...] }` instead"

This temporary error-ing property exists for migration convenience, and will be removed in a future version.

Deprecated

  • Use sort: { $vector: [...] } instead.
vectorize?: "ERROR: Use `sort: { $vectorize: \"...\" }` instead"

This temporary error-ing property exists for migration convenience, and will be removed in a future version.

Deprecated

  • Use sort: { $vectorize: '...' } instead.