Skip to content

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

@henrycjchen

Description

@henrycjchen

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescriptTypes or Types-test related issue / Pull Request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions