Skip to content

Commit fd22f9b

Browse files
committed
fix(query): handle $round with just 1 arg re: code review comments
1 parent 4ec6b40 commit fd22f9b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/helpers/query/cast$expr.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,10 @@ function _castExpression(val, schema, strictQuery) {
119119
}
120120
if (val.$round) {
121121
const $round = val.$round;
122-
if (!Array.isArray($round) || $round.length !== 2) {
122+
if (!Array.isArray($round) || $round.length < 1 || $round.length > 2) {
123123
throw new CastError('Array', $round, '$round');
124124
}
125-
val.$round = [
126-
castNumberOperator($round[0], schema, strictQuery),
127-
castNumberOperator($round[1], schema, strictQuery)
128-
];
125+
val.$round = $round.map(v => castNumberOperator(v, schema, strictQuery));
129126
}
130127

131128
_omitUndefined(val);

test/helpers/query.cast$expr.test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ describe('castexpr', function() {
112112
it('casts $round (gh-13881)', function() {
113113
const testSchema = new Schema({ value: Number });
114114

115-
const res = cast$expr({ $eq: [{ $round: ['$value', '00'] }, 2] }, testSchema);
115+
let res = cast$expr({ $eq: [{ $round: ['$value', '00'] }, 2] }, testSchema);
116116
assert.deepStrictEqual(res, { $eq: [{ $round: ['$value', 0] }, 2] });
117+
118+
res = cast$expr({ $eq: [{ $round: ['$value'] }, 2] }, testSchema);
119+
assert.deepStrictEqual(res, { $eq: [{ $round: ['$value'] }, 2] });
117120
});
118121
});

0 commit comments

Comments
 (0)