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

aggregate command writes results 3 times

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.0-rc0
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None

      Each Document result is written three times, to documentBuilder, resultArray, and result. Using subobjStart() and subarrayStart() only one write to the result buffer would be necessary.

                      BSONArrayBuilder resultArray; // where we'll stash the results
                      for(bool hasDocument = !pSource->eof(); hasDocument;
                          hasDocument = pSource->advance()) {
                          intrusive_ptr<Document> pDocument(pSource->getCurrent());
      
                          /* add the document to the result set */
                          BSONObjBuilder documentBuilder;
                          pDocument->toBson(&documentBuilder);
                          resultArray.append(documentBuilder.done());
                      }
      
                      result.appendArray("result", resultArray.arr());
      

      Observed behavior: The aggregate command copies result documents out multiple times.
      Expected behavior: The aggregate command writes documents directly to the response builder.

            Assignee:
            matt.dannenberg Matt Dannenberg
            Reporter:
            aaron Aaron Staple
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: