Skip to content

Bug: partialFilterExpression on embedded discriminator  #9091

Closed
@andreialecu

Description

@andreialecu

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

When defining an index on a nested discriminator, mongoose knows to change the paths and apply the index on the parent, while properly locating the correct fields within the nested subdocument.

However, the partialFilterExpression is not transformed properly.

Here's an example:

image

The index is defined like this and is part of an embedded schema (child of a parent schema):

  { matchday: 1, team: 1, "players.user": 1 },
  {
    unique: true,
    partialFilterExpression: { "players.user": { $exists: 1 } },
  },

Notice how the indexed fields correctly got nested under invites, but the partialFilterExpression was not updated.

If the current behavior is a bug, please provide the steps to reproduce.

Define an index like the above.

What is the expected behavior?

The partialFilterExpression should be adjusted to point to the correct sub-paths. In the screenshot above, the computed result should be invites.players.user: { $exists: 1 }.

Fixing this could be a breaking change if someone is relying on the currently broken behavior.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

mongoose 5.9.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions