Skip to content

Commit b57efec

Browse files
committed
fix(types): allow $pull with _id
Fix #12142
1 parent 25e4580 commit b57efec

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

test/types/queries.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,16 @@ function gh12091() {
341341
}
342342
update.$addToSet.friendsNames = 'Jane Doe';
343343
}
344+
345+
function gh12142() {
346+
const schema = new Schema({ name: String, comments: [{ text: String }] });
347+
348+
const Test = model('Test', schema);
349+
350+
Test.updateOne(
351+
{ _id: new Types.ObjectId() },
352+
{
353+
$pull: { comments: new Types.ObjectId() }
354+
}
355+
);
356+
}

types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ declare module 'mongoose' {
457457
/** @see https://docs.mongodb.com/manual/reference/operator/update-array/ */
458458
$addToSet?: Mutable<mongodb.SetFields<TSchema>>;
459459
$pop?: AnyKeys<TSchema> & AnyObject;
460-
$pull?: Mutable<mongodb.PullOperator<TSchema>>;
461-
$push?: Mutable<mongodb.PushOperator<TSchema>>;
460+
$pull?: AnyKeys<TSchema> & AnyObject;
461+
$push?: AnyKeys<TSchema> & AnyObject;
462462
$pullAll?: AnyKeys<TSchema> & AnyObject;
463463

464464
/** @see https://docs.mongodb.com/manual/reference/operator/update-bitwise/ */

0 commit comments

Comments
 (0)