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

DocumentSourceGroup does not properly serialize constant expressions, can cause a valid expression on mongos to be unparsable on shards.

    • ALL

      The addToBsonObj calls below should be passed requireExpression == true. I've already written some tests, and the fix is pretty straightforward.

          void DocumentSourceGroup::sourceToBson(
              BSONObjBuilder *pBuilder, bool explain) const {
              BSONObjBuilder insides;
      
              /* add the _id */
              pIdExpression->addToBsonObj(&insides, Document::idName.c_str(), false);
      
              /* add the remaining fields */
              const size_t n = vFieldName.size();
              for(size_t i = 0; i < n; ++i) {
                  intrusive_ptr<Accumulator> pA((*vpAccumulatorFactory[i])(pExpCtx));
                  pA->addOperand(vpExpression[i]);
                  pA->addToBsonObj(&insides, vFieldName[i], false);
              }
      
              pBuilder->append(groupName, insides.done());
          }
      

      May also need to similarly change Accumulator serialization.

            Assignee:
            aaron Aaron Staple
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: