summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/aggregation/bugs/substr.js13
-rw-r--r--src/mongo/db/pipeline/expression.cpp6
2 files changed, 11 insertions, 8 deletions
diff --git a/jstests/aggregation/bugs/substr.js b/jstests/aggregation/bugs/substr.js
index c4eaff7e137..0c7f5bef64d 100644
--- a/jstests/aggregation/bugs/substr.js
+++ b/jstests/aggregation/bugs/substr.js
@@ -1,5 +1,8 @@
// Aggregation $substrBytes tests.
+(function() {
+"use strict";
+
t = db.jstests_aggregation_substr;
t.drop();
@@ -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();