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

$group constant expression fails to re-parse

    • Query Integration
    • Fully Compatible
    • ALL
    • v8.0, v7.0
    • 4

      Tripwire assertion
      error: {'code': 7349401, 'codeName': 'Location7349401', 'errmsg': 'Was not able to re-parse queryStats key when reading queryStats.Status Location17390: $group does not support inclusion-style expressions Hash: 1070139331129839062 Query Shape: { cmdNs: { db: "test", coll: "jstests_indexu_NaN" }, command: "aggregate", pipeline: [ { $group: { _id: { by: 1 }, count: { $sum: 1 } } }, { $sort: { count: -1 } } ] }'}
      location: {fileName:"src/mongo/db/pipeline/document_source_query_stats.cpp", line:255, functionName:"toDocument"} 

      The failing query:

      db.c.aggregate([{ $sortByCount: { $expr: { 'by': 22 } } }]) 

      which desugars to

      db.c.aggregate([{ $group: { _id: {$expr: { 'by': 22 }, count: { $sum: 1 } } }, { $sort: { count: -1 } } ])

      It's hitting this assertion. This is happening because when we parse $expr: { 'by': 22 } we drop the $expr and by: 22 looks like a group expression on the field name "by" with the expression being "22". This is not allowed per the assertion we hit. What we really want is pre-SERVER-84159 behavior that serializes constant expressions with $const in the representative shape so that they are not interpreted as raw constants in cases when that's not allowed during the re-parsing step.

            Assignee:
            alyssa.clark@mongodb.com Alyssa Clark
            Reporter:
            alyssa.clark@mongodb.com Alyssa Clark
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: