summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2016-08-18 16:19:10 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2016-08-19 12:08:21 -0400
commit63ab48a951c152d14a6d1662e2cfc5fcb4ccea06 (patch)
treef2f4d3e700d1843b7d0d87864f470f05d389b3b9 /jstests/aggregation
parent78c06c7e342bb159bcf22c85502cb7db3a695ffd (diff)
downloadmongo-63ab48a951c152d14a6d1662e2cfc5fcb4ccea06.tar.gz
SERVER-25439 Modernize jstests/aggregation/bugs/server5209.js
Diffstat (limited to 'jstests/aggregation')
-rw-r--r--jstests/aggregation/bugs/server5209.js15
-rw-r--r--jstests/aggregation/sources/group/numeric_grouping.js25
2 files changed, 25 insertions, 15 deletions
diff --git a/jstests/aggregation/bugs/server5209.js b/jstests/aggregation/bugs/server5209.js
deleted file mode 100644
index 8c0f017bbc7..00000000000
--- a/jstests/aggregation/bugs/server5209.js
+++ /dev/null
@@ -1,15 +0,0 @@
-// use qa
-db = db.getSiblingDB('qa');
-
-db.aggtype.drop();
-db.aggtype.insert({key: NumberInt(24), value: 17});
-db.aggtype.insert({key: NumberLong(24), value: 8});
-db.aggtype.insert({key: 24, value: 5});
-db.aggtype.insert({key: NumberInt(42), value: 11});
-db.aggtype.insert({key: NumberLong(42), value: 13});
-db.aggtype.insert({key: 42, value: 6});
-
-var at = db.aggtype.aggregate({$group: {_id: "$key", s: {$sum: "$value"}}}).toArray();
-
-assert(at[0].s == 30, 'server5209 failed');
-assert(at[1].s == 30, 'server5209 failed');
diff --git a/jstests/aggregation/sources/group/numeric_grouping.js b/jstests/aggregation/sources/group/numeric_grouping.js
new file mode 100644
index 00000000000..c55dee564de
--- /dev/null
+++ b/jstests/aggregation/sources/group/numeric_grouping.js
@@ -0,0 +1,25 @@
+/**
+ * Tests that numbers that are equivalent but have different types are grouped together.
+ */
+(function() {
+ "use strict";
+ const coll = db.numeric_grouping;
+
+ coll.drop();
+
+ assert.writeOK(coll.insert({key: new NumberInt(24), value: 17}));
+ assert.writeOK(coll.insert({key: new NumberLong(24), value: 8}));
+ assert.writeOK(coll.insert({key: 24, value: 5}));
+
+ assert.writeOK(coll.insert({key: new NumberInt(42), value: 11}));
+ assert.writeOK(coll.insert({key: new NumberLong(42), value: 13}));
+ assert.writeOK(coll.insert({key: 42, value: 6}));
+
+ const results = coll.aggregate({$group: {_id: "$key", s: {$sum: "$value"}}}).toArray();
+
+ assert.eq(results.length, 2, tojson(results));
+
+ // Both groups should sum to 30.
+ assert.eq(results[0].s, 30, tojson(results));
+ assert.eq(results[1].s, 30, tojson(results));
+}());