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

findOneAndUpdate does not cast arrayFilters #13219

Closed
2 tasks done
dermasmid opened this issue Mar 27, 2023 · 1 comment · Fixed by #13220
Closed
2 tasks done

findOneAndUpdate does not cast arrayFilters #13219

dermasmid opened this issue Mar 27, 2023 · 1 comment · Fixed by #13220
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@dermasmid
Copy link
Contributor

dermasmid commented Mar 27, 2023

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

Node.js version

18

MongoDB server version

5

Typescript version (if applicable)

No response

Description

when using findOneAndUpdate and arrayFilters it will not be casted, resulting in _id not being a ObjectId

introduced in 3174e29

Steps to Reproduce

Model.findOneAndUpdate( { _id: '636bb1a6dece391b2652ae18' }, { $set: { 'versions.$[v].test': 'test', }, }, { arrayFilters: [ { 'v._id': '637601b33ce5bbf2cbfe3831' }, ], } ).exec()

Expected Behavior

_id should be converted to ObjectId

dermasmid added a commit to Triple-Whale/mongoose that referenced this issue Mar 27, 2023
@dermasmid dermasmid mentioned this issue Mar 27, 2023
@Ruslancic
Copy link

I have similar error with this code:

Model.findByIdAndUpdate(
            id,
            {
              $inc: { 'item.$[elem].items': -1 },
            },
            { new: true, arrayFilters: [{ 'elem._id': item._id }] },
          );

Increment by -1 not working!

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Mar 28, 2023
@vkarpov15 vkarpov15 added this to the 7.0.4 milestone Apr 3, 2023
vkarpov15 added a commit that referenced this issue Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants