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

Cast array filters with embedded discriminators in arrays doesn't work #15053

Open
2 tasks done
jeffersonlipsky opened this issue Nov 22, 2024 · 0 comments
Open
2 tasks done

Comments

@jeffersonlipsky
Copy link
Contributor

Prerequisites

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

Mongoose version

7.4.0

Node.js version

18.0

MongoDB server version

8.0

Typescript version (if applicable)

5.4.3

Description

When I made an update with arrayFilters in a schema with an embedded discriminators property the method castArrayFilters didn't know the discriminated properties. So Mongoose throws an error "Could not find path "pathDiscriminated" in schema"

Steps to Reproduce

So, You made an update with arrayFilters like the following:
model.updateManyWithDeleted( filter, { $set: 'items.$[a].ping': 'test'}, { arrayFilters: ['a.kind': 'one'] }, );

And you have a schema like the following

``
const ItemSchema = new Schema({ message: String }, { discriminatorKey: 'kind', _id: false });

const MainSchema = new Schema({ items: [ItemSchema] });

const path = MainSchema.path<MongooseSchema.Types.Array>('items');

const Onechema = new Schema({ping:String});
const TwoSchema = new Schema({pong:String});

path.discriminator('one', Onechema);
path.discriminator('two, TwoSchema);
``

Partial call stack:
at _castArrayFilters (../node_modules/mongoose/lib/helpers/update/castArrayFilters.js:100:15) at castArrayFilters (../node_modules/mongoose/lib/helpers/update/castArrayFilters.js:28:3)

Inside method getPath the method schema.path doesn't know the discriminated properties
Image
Image
Image

And the path method doesn't check in the discriminators
Image

Expected Behavior

The castArrayFilters, also check inside discriminators paths

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant