From c52f9e78ed5649f4a608adf26e0ffd3fbbe436dd Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 29 Aug 2024 11:50:41 -0400 Subject: [PATCH 1/2] types(query): add $expr to RootQuerySelector Fix #14841 Re: #14764 --- test/types/queries.test.ts | 6 ++++++ types/query.d.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/test/types/queries.test.ts b/test/types/queries.test.ts index 5396f384cad..cafb98949cf 100644 --- a/test/types/queries.test.ts +++ b/test/types/queries.test.ts @@ -672,3 +672,9 @@ async function gh14545() { const myProjection = await M.findOne({}).select({ prop: 1 }).exec(); expectType(myProjection); } + +function gh14841() { + const filter: FilterQuery<{ owners: string[] }> = { + $expr: { $lt: [{ $size: "$owners" }, 10] }, + }; +} \ No newline at end of file diff --git a/types/query.d.ts b/types/query.d.ts index 572ec33e1df..0df0388c3d4 100644 --- a/types/query.d.ts +++ b/types/query.d.ts @@ -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; // 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) From 47950f42d559c18a6b9b6fb5445098ee12df955e Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 29 Aug 2024 15:23:30 -0400 Subject: [PATCH 2/2] style: fix lint --- test/types/queries.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/types/queries.test.ts b/test/types/queries.test.ts index cafb98949cf..02998362434 100644 --- a/test/types/queries.test.ts +++ b/test/types/queries.test.ts @@ -675,6 +675,6 @@ async function gh14545() { function gh14841() { const filter: FilterQuery<{ owners: string[] }> = { - $expr: { $lt: [{ $size: "$owners" }, 10] }, + $expr: { $lt: [{ $size: '$owners' }, 10] } }; -} \ No newline at end of file +}