diff --git a/index.d.ts b/index.d.ts index a542e62f81a..38d87dd7a30 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1079,7 +1079,7 @@ declare module 'mongoose' { omitUndefined?: boolean; overwrite?: boolean; overwriteDiscriminatorKey?: boolean; - populate?: string; + populate?: string | string[] | PopulateOptions | PopulateOptions[]; projection?: any; /** * if true, returns the raw result from the MongoDB driver diff --git a/test/typescript/queries.ts b/test/typescript/queries.ts index 6f56f775558..5d5f9c07b58 100644 --- a/test/typescript/queries.ts +++ b/test/typescript/queries.ts @@ -1,13 +1,18 @@ -import { Schema, model, Document, Types, Query, Model, QueryWithHelpers } from 'mongoose'; +import { Schema, model, Document, Types, Query, Model, QueryWithHelpers, PopulatedDoc } from 'mongoose'; +import { ObjectId } from 'mongodb'; interface QueryHelpers { _byName(this: QueryWithHelpers, name: string): QueryWithHelpers, ITest, QueryHelpers>; byName(name: string): QueryWithHelpers, ITest, QueryHelpers>; } +const childSchema: Schema = new Schema({ name: String }); +const ChildModel = model('Child', childSchema); + const schema: Schema> = new Schema({ name: { type: 'String' }, tags: [String], + child: { type: 'ObjectId', ref: 'Child' }, docs: [{ _id: 'ObjectId', id: Number, tags: [String] }], endDate: Date }); @@ -21,6 +26,9 @@ schema.query.byName = function(name: string): QueryWithHelpers { return this._byName(name); }; +interface Child { + name: string; +} interface ISubdoc extends Document { myId?: Types.ObjectId; id?: number; @@ -31,6 +39,7 @@ interface ITest extends Document { name?: string; age?: number; parent?: Types.ObjectId; + child?: PopulatedDoc>, tags?: string[]; docs?: ISubdoc[]; endDate?: Date; @@ -38,6 +47,8 @@ interface ITest extends Document { const Test = model>('Test', schema); +Test.find({}, {}, {populate:{path:"child", model:ChildModel, match:true}}).exec().then((res: Array) => console.log(res)) + Test.find().byName('test').byName('test2').orFail().exec().then(console.log); Test.count({ name: /Test/ }).exec().then((res: number) => console.log(res));