Skip to content

Commit

Permalink
Merge pull request #14845 from Automattic/vkarpov15/gh-14841
Browse files Browse the repository at this point in the history
types(query): add $expr to RootQuerySelector
  • Loading branch information
vkarpov15 authored Sep 3, 2024
2 parents cf8c8e1 + 47950f4 commit 4b1aadc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/types/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,9 @@ async function gh14545() {
const myProjection = await M.findOne({}).select<SlimTest>({ prop: 1 }).exec();
expectType<SlimTestDocument | null>(myProjection);
}

function gh14841() {
const filter: FilterQuery<{ owners: string[] }> = {
$expr: { $lt: [{ $size: '$owners' }, 10] }
};
}
1 change: 1 addition & 0 deletions types/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ declare module 'mongoose' {
$where?: string | Function;
/** @see https://www.mongodb.com/docs/manual/reference/operator/query/comment/#op._S_comment */
$comment?: string;
$expr?: Record<string, any>;
// we could not find a proper TypeScript generic to support nested queries e.g. 'user.friends.name'
// this will mark all unrecognized properties as any (including nested queries) only if
// they include a "." (to avoid generically allowing any unexpected keys)
Expand Down

0 comments on commit 4b1aadc

Please sign in to comment.