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

fix(castArrayFilters): handle casting on all fields of array filter #9122

Merged
merged 2 commits into from
Jun 12, 2020
Merged

Conversation

lafeuil
Copy link

@lafeuil lafeuil commented Jun 12, 2020

Summary

When specified an array filter for an update query, only the first field of the filter object is cast.

With this merge request, all fields of the filter are iterated and cast.
Examples

    const schema = new Schema({
      comments: [{
        text: String,
        replies: [{ 
          beginAt: Date, 
          endAt: Date
        }]
      }]
    });
    const q = new Query();
    q.schema = schema;

    q.updateOne({}, { $set: { 'comments.$[x].replies.$[y].endAt': '2019-01-01' } }, {
      arrayFilters: [{ 'x.text': 123 }, { 'y.beginAt': { $gte: '2018-01-01' }, 'y.endAt': { $lt: '2020-01-01' } }]
    });

The endAt field in array filter is not cast to Date.

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thanks 👍

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

Successfully merging this pull request may close these issues.

2 participants