[SERVER-26461] $meta : "textScore" returns null when used inside $group in aggregation and no other fields are needed Created: 05/Oct/16  Updated: 19/Nov/16  Resolved: 14/Oct/16

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 3.3.15
Fix Version/s: 3.4.0-rc1

Type: Bug Priority: Major - P3
Reporter: Jai Hirsch Assignee: Charlie Swanson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File repro.js    
Issue Links:
Depends
Duplicate
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

db.text.drop()
 
assert.writeOK(db.text.insert({ "_id" : 1, "title" : "cakes and ale" }))
assert.writeOK(db.text.insert({ "_id" : 2, "title" : "more cakes" }))
assert.writeOK(db.text.insert({ "_id" : 3, "title" : "bread" }))
assert.writeOK(db.text.insert({ "_id" : 4, "title" : "some cakes" }))
 
assert.commandWorked(db.text.createIndex({ title : "text" }))
 
shellPrint(db.text.aggregate(
   [
     { $match: { $text: { $search: "cake" } } },
     { $group: { _id: { $meta: "textScore" }, count: { $sum: 1 } } }
   ]
))

Sprint: Query 2016-10-31
Participants:
Case:
Linked BF Score: 0

 Description   

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



 Comments   
Comment by Githook User [ 14/Oct/16 ]

Author:

{u'username': u'cswanson310', u'name': u'Charlie Swanson', u'email': u'charlie.swanson@mongodb.com'}

Message: SERVER-26461 Don't exclude fields when entire document is needed.
Branch: master
https://github.com/mongodb/mongo/commit/6966320283172b9c92556c7fe9b952dec341f9d1

Comment by Charlie Swanson [ 14/Oct/16 ]

Re-opening since I accidentally broke the build.

Comment by Githook User [ 14/Oct/16 ]

Author:

{u'username': u'cswanson310', u'name': u'Charlie Swanson', u'email': u'cswanson310@gmail.com'}

Message: SERVER-26461 Request text score even if no fields are needed.
Branch: master
https://github.com/mongodb/mongo/commit/805b4bdc9473ad1841fca738ebed80c7b2047a84

Comment by Charlie Swanson [ 07/Oct/16 ]

Thanks for the report jaihirsch@carfax.com! I've tracked down the problem and updated the description accordingly.

Generated at Thu Feb 08 04:12:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.