diff options
author | Junhson Jean-Baptiste <junhson.jean-baptiste@mongodb.com> | 2020-06-25 21:35:41 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-01 20:33:42 +0000 |
commit | e7e4e0707a1be7ae27a129373f0e00888e9f9aea (patch) | |
tree | 6ee2fb5695fe7951b3c87bc90d215314c0861ea9 | |
parent | 07deced6b3fa2f5927bb33bd4940cc60d6bc4607 (diff) | |
download | mongo-e7e4e0707a1be7ae27a129373f0e00888e9f9aea.tar.gz |
SERVER-37068 Add NumberDecimal as numeric type for aggregation expressions
-rw-r--r-- | jstests/aggregation/bugs/substr.js | 15 | ||||
-rw-r--r-- | src/mongo/db/pipeline/expression.cpp | 6 |
2 files changed, 12 insertions, 9 deletions
diff --git a/jstests/aggregation/bugs/substr.js b/jstests/aggregation/bugs/substr.js index c4eaff7e137..66ad4a75253 100644 --- a/jstests/aggregation/bugs/substr.js +++ b/jstests/aggregation/bugs/substr.js @@ -1,6 +1,9 @@ // Aggregation $substrBytes tests. -t = db.jstests_aggregation_substr; +(function() { +"use strict"; + +let t = db.jstests_aggregation_substr; t.drop(); t.save({}); @@ -45,10 +48,11 @@ assertException('abcd', -10, 0); // Additional numeric types for offset / length. assertSubstring('bc', 'abcd', 1, 2); assertSubstring('bc', 'abcd', 1.0, 2.0); -assertSubstring('bc', 'abcd', NumberInt(1), NumberInt(2)); -assertSubstring('bc', 'abcd', NumberLong(1), NumberLong(2)); -assertSubstring('bc', 'abcd', NumberInt(1), NumberLong(2)); -assertSubstring('bc', 'abcd', NumberLong(1), NumberInt(2)); +assertSubstring('bc', 'abcd', NumberInt("1"), NumberInt("2")); +assertSubstring('bc', 'abcd', NumberLong("1"), NumberLong("2")); +assertSubstring('bc', 'abcd', NumberInt("1"), NumberLong("2")); +assertSubstring('bc', 'abcd', NumberLong("1"), NumberInt("2")); +assertSubstring('bc', 'abcd', NumberDecimal("1"), NumberDecimal("2")); // Integer component is used. assertSubstring('bc', 'abcd', 1.2, 2.2); assertSubstring('bc', 'abcd', 1.9, 2.9); @@ -133,3 +137,4 @@ assert.eq( }) .toArray()[0] .a); +}()); diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index 80400576bf0..f1f55f6d4d3 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -4472,13 +4472,11 @@ Value ExpressionSubstrBytes::evaluate(const Document& root, Variables* variables str::stream() << getOpName() << ": starting index must be a numeric type (is BSON type " << typeName(pLower.getType()) << ")", - (pLower.getType() == NumberInt || pLower.getType() == NumberLong || - pLower.getType() == NumberDouble)); + pLower.numeric()); uassert(16035, str::stream() << getOpName() << ": length must be a numeric type (is BSON type " << typeName(pLength.getType()) << ")", - (pLength.getType() == NumberInt || pLength.getType() == NumberLong || - pLength.getType() == NumberDouble)); + pLength.numeric()); const long long signedLower = pLower.coerceToLong(); |