Skip to content

Commit 5c0140c

Browse files
committedAug 23, 2021
fix(index.d.ts): add match to VirtualTypeOptions.options
Fix #8479
1 parent 6122f4b commit 5c0140c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
 

‎index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ declare module 'mongoose' {
18231823
perDocumentLimit?: number;
18241824

18251825
/** Additional options like `limit` and `lean`. */
1826-
options?: QueryOptions;
1826+
options?: QueryOptions & { match?: AnyObject };
18271827

18281828
/** Additional options for plugins */
18291829
[extra: string]: any;

‎test/typescript/virtuals.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface IPerson {
1010

1111
interface IPet {
1212
name: string;
13+
isDeleted: boolean;
1314
ownerId: number;
1415

1516
owner: IPerson;
@@ -23,7 +24,8 @@ const personSchema = new Schema<IPerson & Document, Model<IPerson & Document>, I
2324

2425
const petSchema = new Schema<IPet & Document, Model<IPet & Document>, IPet>({
2526
name: { type: String, required: true },
26-
ownerId: { type: Number, required: true }
27+
ownerId: { type: Number, required: true },
28+
isDeleted: { type: Boolean, default: false }
2729
});
2830

2931
// Virtual getters and setters
@@ -43,7 +45,10 @@ petSchema.virtual('owner', {
4345
localField: 'ownerId',
4446
foreignField: '_id',
4547
justOne: true,
46-
autopopulate: true
48+
autopopulate: true,
49+
options: {
50+
match: { isDeleted: false }
51+
}
4752
});
4853

4954
const Person = model('Person', personSchema);

0 commit comments

Comments
 (0)
Please sign in to comment.