-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: cast error when there is an elemMatch in the and clause #14171
fix: cast error when there is an elemMatch in the and clause #14171
Conversation
lib/schema/array.js
Outdated
@@ -637,15 +637,15 @@ handle.$or = createLogicalQueryOperatorHandler('$or'); | |||
handle.$and = createLogicalQueryOperatorHandler('$and'); | |||
handle.$nor = createLogicalQueryOperatorHandler('$nor'); | |||
|
|||
function createLogicalQueryOperatorHandler(op) { | |||
return function logicalQueryOperatorHandler(val) { | |||
function createLogicalQueryOperatorHandler(op, context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem necessary to take context
as an argument in this scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is LGTM, but can you please add a test case?
130dcec
to
b052e65
Compare
@@ -791,6 +791,38 @@ describe('model query casting', function() { | |||
assert.ok(res); | |||
assert.deepStrictEqual(res.map(doc => doc.arr[1].id), ['two', 'three']); | |||
}); | |||
|
|||
it('should not throw a cast error when dealing with an array of objects in combination with $elemMatch and nested $and', async function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits: I couldn't think of an appropriate test name, so I'm open to suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
Summary
Examples
query: