Skip to content

Commit e100129

Browse files
committed
fix: cast error when there is an elemMatch in the and clause
1 parent aa4b38a commit e100129

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/schema/array.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,15 +637,15 @@ handle.$or = createLogicalQueryOperatorHandler('$or');
637637
handle.$and = createLogicalQueryOperatorHandler('$and');
638638
handle.$nor = createLogicalQueryOperatorHandler('$nor');
639639

640-
function createLogicalQueryOperatorHandler(op) {
641-
return function logicalQueryOperatorHandler(val) {
640+
function createLogicalQueryOperatorHandler(op, context) {
641+
return function logicalQueryOperatorHandler(val, context) {
642642
if (!Array.isArray(val)) {
643643
throw new TypeError('conditional ' + op + ' requires an array');
644644
}
645645

646646
const ret = [];
647647
for (const obj of val) {
648-
ret.push(cast(this.casterConstructor.schema, obj, null, this && this.$$context));
648+
ret.push(cast(this.casterConstructor.schema ?? context.schema, obj, null, this && this.$$context));
649649
}
650650

651651
return ret;

0 commit comments

Comments
 (0)