Interface VirtualTypeOptions<HydratedDocType, DocType>

interface VirtualTypeOptions<HydratedDocType, DocType> {
    count?: boolean;
    foreignField?: string | ((this, doc) => string);
    getters?: boolean;
    justOne?: boolean;
    limit?: number;
    localField?: string | ((this, doc) => string);
    match?: FilterQuery<any> | ((doc, virtual?) => Record<string, any>);
    options?: mongoose.QueryOptions<DocType> & {
        match?: AnyObject;
    };
    perDocumentLimit?: number;
    ref?: string | Function;
    skip?: number;
    [extra: string]: any;
}

Type Parameters

Indexable

[extra: string]: any

Additional options for plugins

Properties

count?: boolean

If you set this to true, populate() will set this virtual to the number of populated documents, as opposed to the documents themselves, using Query#countDocuments().

foreignField?: string | ((this, doc) => string)

The foreign field to populate on if this is a populated virtual.

Type declaration

getters?: boolean

If you set this to true, Mongoose will call any custom getters you defined on this virtual.

justOne?: boolean

By default, a populated virtual is an array. If you set justOne, the populated virtual will be a single doc or null.

limit?: number

Add a default limit to the populate() query.

localField?: string | ((this, doc) => string)

The local field to populate on if this is a populated virtual.

Type declaration

match?: FilterQuery<any> | ((doc, virtual?) => Record<string, any>)

Add an extra match condition to populate().

Type declaration

    • (doc, virtual?): Record<string, any>
    • Parameters

      • doc: Record<string, any>
      • Optional virtual: this

      Returns Record<string, any>

options?: mongoose.QueryOptions<DocType> & {
    match?: AnyObject;
}

Additional options like limit and lean.

Type declaration

perDocumentLimit?: number

For legacy reasons, limit with populate() may give incorrect results because it only executes a single query for every document being populated. If you set perDocumentLimit, Mongoose will ensure correct limit per document by executing a separate query for each document to populate(). For example, .find().populate({ path: 'test', perDocumentLimit: 2 }) will execute 2 additional queries if .find() returns 2 documents.

ref?: string | Function

If ref is not nullish, this becomes a populated virtual.

skip?: number

Add a default skip to the populate() query.