Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
None
Description
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.