summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorCharlie Swanson <cswanson310@gmail.com>2016-10-13 16:49:53 -0400
committerCharlie Swanson <cswanson310@gmail.com>2016-10-14 11:20:17 -0400
commit805b4bdc9473ad1841fca738ebed80c7b2047a84 (patch)
tree144a8cbaa2abecab75136f1d0c0c011e8ac6e871 /jstests
parent4b06a21895f292f45f58659a2e674d4e80e65614 (diff)
downloadmongo-805b4bdc9473ad1841fca738ebed80c7b2047a84.tar.gz
SERVER-26461 Request text score even if no fields are needed.
Diffstat (limited to 'jstests')
-rw-r--r--jstests/aggregation/bugs/server22093.js8
-rw-r--r--jstests/aggregation/sources/group/text_score_grouping.js31
2 files changed, 39 insertions, 0 deletions
diff --git a/jstests/aggregation/bugs/server22093.js b/jstests/aggregation/bugs/server22093.js
index bf91eb89e43..ff8fda9c666 100644
--- a/jstests/aggregation/bugs/server22093.js
+++ b/jstests/aggregation/bugs/server22093.js
@@ -38,4 +38,12 @@ load('jstests/libs/analyze_plan.js');
]);
assert(planHasStage(explained.stages[0].$cursor.queryPlanner.winningPlan, "COUNT_SCAN"));
+
+ // Make sure a $count stage can use the COUNT_SCAN optimization.
+ explained = coll.explain().aggregate([{$match: {foo: {$gt: 0}}}, {$count: "count"}]);
+ assert(planHasStage(explained.stages[0].$cursor.queryPlanner.winningPlan, "COUNT_SCAN"));
+
+ // A $match that is not a single range cannot use the COUNT_SCAN optimization.
+ explained = coll.explain().aggregate([{$match: {foo: {$in: [0, 1]}}}, {$count: "count"}]);
+ assert(!planHasStage(explained.stages[0].$cursor.queryPlanner.winningPlan, "COUNT_SCAN"));
}());
diff --git a/jstests/aggregation/sources/group/text_score_grouping.js b/jstests/aggregation/sources/group/text_score_grouping.js
new file mode 100644
index 00000000000..bb65d77fd00
--- /dev/null
+++ b/jstests/aggregation/sources/group/text_score_grouping.js
@@ -0,0 +1,31 @@
+/**
+ * Tests that a user can group on the text score.
+ */
+(function() {
+ "use strict";
+ const coll = db.text_score_grouping;
+
+ coll.drop();
+
+ assert.writeOK(coll.insert({"_id": 1, "title": "cakes"}));
+ assert.writeOK(coll.insert({"_id": 2, "title": "cookies and cakes"}));
+
+ assert.commandWorked(coll.createIndex({title: "text"}));
+
+ // Make sure there are two distinct groups for a text search with no other dependencies.
+ var results = coll.aggregate([
+ {$match: {$text: {$search: "cake cookies"}}},
+ {$group: {_id: {$meta: "textScore"}, count: {$sum: 1}}}
+ ])
+ .toArray();
+ assert.eq(results.length, 2);
+
+ // Make sure there are two distinct groups if there are other fields required by the group.
+ results = coll.aggregate([
+ {$match: {$text: {$search: "cake cookies"}}},
+ {$group: {_id: {$meta: "textScore"}, firstId: {$first: "$_id"}}}
+ ])
+ .toArray();
+ assert.eq(results.length, 2);
+
+}());