UNPKG

1.38 kBTypeScriptView Raw
1declare module 'mongoose' {
2
3 /**
4 * Reference another Model
5 */
6 type PopulatedDoc<
7 PopulatedType,
8 RawId extends RefType = (PopulatedType extends { _id?: RefType; } ? NonNullable<PopulatedType['_id']> : Types.ObjectId) | undefined
9 > = PopulatedType | RawId;
10
11 interface PopulateOptions {
12 /** space delimited path(s) to populate */
13 path: string;
14 /** fields to select */
15 select?: any;
16 /** query conditions to match */
17 match?: any;
18 /** optional model to use for population */
19 model?: string | Model<any>;
20 /** optional query options like sort, limit, etc */
21 options?: QueryOptions;
22 /** correct limit on populated array */
23 perDocumentLimit?: number;
24 /** optional boolean, set to `false` to allow populating paths that aren't in the schema */
25 strictPopulate?: boolean;
26 /** deep populate */
27 populate?: string | PopulateOptions | (string | PopulateOptions)[];
28 /**
29 * If true Mongoose will always set `path` to an array, if false Mongoose will
30 * always set `path` to a document. Inferred from schema by default.
31 */
32 justOne?: boolean;
33 /** transform function to call on every populated doc */
34 transform?: (doc: any, id: any) => any;
35 }
36
37 interface PopulateOption {
38 populate?: string | string[] | PopulateOptions | PopulateOptions[];
39 }
40}