summaryrefslogtreecommitdiff
path: root/jstests/aggregation/bugs
diff options
context:
space:
mode:
authorSteve Tarzia <steve.tarzia@mongodb.com>2022-03-07 23:02:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-09 20:17:22 +0000
commit3fe0851620a782f703e722e37afa05460986c81f (patch)
tree0b560b95198c2db20256b2434f20380388a76e4e /jstests/aggregation/bugs
parent2c7c06c4defd5f56d9b71225917f28397766aa12 (diff)
downloadmongo-3fe0851620a782f703e722e37afa05460986c81f.tar.gz
SERVER-62242 fixed $indexOfArray handling of duplicate vals in const arrays
Diffstat (limited to 'jstests/aggregation/bugs')
-rw-r--r--jstests/aggregation/bugs/server62242.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/jstests/aggregation/bugs/server62242.js b/jstests/aggregation/bugs/server62242.js
new file mode 100644
index 00000000000..273dddbf16d
--- /dev/null
+++ b/jstests/aggregation/bugs/server62242.js
@@ -0,0 +1,32 @@
+// SERVER-62242
+// $indexOfArray does not work with duplicate values in array
+(function() {
+"use strict";
+
+const c = db[jsTest.name()];
+c.drop();
+
+c.save({_id: 0, number: 222});
+
+// before SERVER-62242, this incorrectly returned {_id: 0, number: 222, idx: -1}
+assert.eq(
+ [{_id: 0, number: 222, idx: 2}],
+ c.aggregate([{$addFields: {idx: {$indexOfArray: [[111, 111, 222], "$number"]}}}]).toArray());
+
+// this query was OK
+assert.eq([{_id: 0, number: 222, idx: 2}],
+ c.aggregate([
+ {$addFields: {idx: {$indexOfArray: [[111, 111, 222, 333], "$number"]}}}
+ ]).toArray());
+
+// also test for cases where a range is specified
+assert.eq([{_id: 0, number: 222, idx: -1}],
+ c.aggregate([
+ {$addFields: {idx: {$indexOfArray: [[111, 111, 222, 333], "$number", 0, 1]}}}
+ ]).toArray());
+
+assert.eq([{_id: 0, number: 222, idx: 3}],
+ c.aggregate([
+ {$addFields: {idx: {$indexOfArray: [[111, 111, 222, 222, 333], "$number", 3, 5]}}}
+ ]).toArray());
+})();