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

Add missing types for $firstN, $lastN, $bottom, $bottomN, $minN and $maxN operators #15299

Open
2 tasks done
henrycjchen opened this issue Mar 5, 2025 · 0 comments
Open
2 tasks done
Labels
typescript Types or Types-test related issue / Pull Request

Comments

@henrycjchen
Copy link

henrycjchen commented Mar 5, 2025

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.13.8

Node.js version

22.12.0

MongoDB server version

6.0.17

Typescript version (if applicable)

5.7.2

Description

MongoDB 5.2 introduced several new accumulation operators, including $top, $topN, $firstN, $lastN, $minN and $maxN. While $top and $topN work as expected, the other operators currently cause TypeScript errors when used with Mongoose.

Steps to Reproduce

Query:

GameEntry.aggregate([
  {
     $sort: { score: -1 }
  },
  {
     $group: {
       _id: '$gameId',
      maxScores: {
        $firstN: { input: '$score', n: 3 }
     }  
  }
]);

Error:
Object literal may only specify known properties, and $firstN does not exist in type AccumulatorOperator

Expected Behavior

Expected $firstN, $lastN, $minN, $maxN, $bottom and $bottomN to be supported as aggregation operators on v6(v7 might be needed too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

2 participants