-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 3.3.15
-
Component/s: Aggregation Framework
-
None
-
Fully Compatible
-
ALL
-
-
Query 2016-10-31
-
(copied to CRM)
-
0
Our work to optimize $group to take advantage of COUNT_SCAN plans accidentally introduced this regression. Specifically, this change made it so that we will no longer request the text score from the query system if our only dependency is the text score.
Original Description
$meta : "textScore" returns null when used inside $group in aggregation under 3.3.15:
> db.text.aggregate( [ { $match: { $text: { $search: "cake" } } }, { $group: { _id: { $meta: "textScore" }, count: { $sum: 1 } } } ] ) { "_id" : null, "count" : 3 }
Attached is a script repro.js that reproduces this problem.
The behavior is correct on 3.2.10 and 3.0.12 where the same aggregation returns:
{ "_id" : 1, "count" : 2 } { "_id" : 0.75, "count" : 1 }
If $meta : "textScore" is used in $project, it works fine:
test> db.text.aggregate( ... [ ... { $match: { $text: { $search: "cake" } } }, ... { $project : { score: { $meta: "textScore" }}} ... ] ... ) { "result": [ { "_id": 1, "score": 0.75 }, { "_id": 2, "score": 1 }, { "_id": 4, "score": 1 } ], "ok": 1 } test>
as well as if used in find():
test> db.text.find({ $text : { $search : "cake" }},{ score: { $meta: "textScore" }}) { "_id": 1, "title": "cakes and ale", "score": 0.75 } { "_id": 2, "title": "more cakes", "score": 1 } { "_id": 4, "title": "some cakes", "score": 1 } Fetched 3 record(s) in 2ms test>
The example is from https://docs.mongodb.com/v3.2/reference/operator/aggregation/meta/#examples