Skip to content

Typings: New Aggregation Type Issues [DateExpressionOperatorReturningNumber, AddToSet, ...] #12017

@MichaelFedora

Description

@MichaelFedora

Prerequisites

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

Running:

  • Mongoose 6.4.1
  • Typescript 4.7.4
  • Node 14.19.1

Issue

This new update has messed up a log of my aggregation typings (like others).

1. Add DateExpressionOperatorReturningNumber to NumberExpression

This doesn't work currently, but it should. I believe it was forgotten:

const a: Expression = { $subtract: [
  { $dayOfWeek: new Date() } as Expression.DayOfWeek, // errors
  2
] };

2. Some stages and operators specify "Expressions" when they can take values as well

This breaks quite a few things ($addToSet as well):

const a: Expression.Reduce = {
  $reduce: {
    input: '$values',
    initialValue: { depth: -1 }, // errors
    in: {
      depth: '$$this.depth' // errors
    }
  }
};

const b: Expression.Reduce = {
  $reduce: {
    input: '$values',
    initialValue: 0, // errors
    in: { $add: ['$$value', '$$this'] }
  }
};

const c: PipelineStage.Set = {
  $set: {
    child: {
      foo: 'bar' // errors
    },
    friend: new ObjectId() // errors
  }
};

const a: Expression.ToInt = { $toInt: 2.5 }; // errors

3. AddToSet requires ArrayExpression

According to the docs it just takes an "expression" ( https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/ ).

4. Cond doesn't allow nested Conds

...because it is too strict on the first requirement being a BooleanExpression. I think switching most operators to accept a ConditionalExpressionOperator (with a <T> or otherwise) would help a lot, because IfNull is also throwing things.


Otherwise, reintroducing the old Pipeline type and/or having a more flexible Pipeline type in parallel, if we wanted/needed less strict checks would be great.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions