An object to define some options when including other relational fields.

interface IncludeObject {
    as?: string;
    collectionName: string;
    countItems?: boolean;
    fieldName: string;
    foreignField?: string;
    maxItems?: number;
    sort?: {
        [propertyName: string]: 1 | -1;
    };
}

Properties

as?: string

Custom return name for included items. Defaults to fieldName.

collectionName: string

Collection of referenced item/s (only collection name)

countItems?: boolean

Enable counting total items or not. Defaults to false.

fieldName: string

Property/field name of referenced items in the current item.

foreignField?: string

Foreign field name. Defaults to _id.

maxItems?: number

Maximum number of items to include. Defaults to 50.

sort?: {
    [propertyName: string]: 1 | -1;
}

By default all referenced items are sorted via _createdDate field in ascending order (1) but you can customize that stage too!