Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(query): add $expr to RootQuerySelector #14845

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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