diff --git a/test/types/queries.test.ts b/test/types/queries.test.ts index 5396f384cad..02998362434 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] } + }; +} 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)