Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-26461

$meta : "textScore" returns null when used inside $group in aggregation and no other fields are needed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.3.15
    • Fix Version/s: 3.4.0-rc1
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      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 } } }
         ]
      ))
      

      Show
      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
    • 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

        Attachments

          Activity

            People

            Assignee:
            charlie.swanson Charlie Swanson
            Reporter:
            jaihirsch@carfax.com Jai Hirsch
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: