summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/query_request.cpp
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2016-08-16 14:53:58 -0400
committerKyle Suarez <kyle.suarez@mongodb.com>2016-08-16 15:07:49 -0400
commite7661304b820b16ad51f4485617031f9188b9229 (patch)
tree878287de46ccb80ea914b7bd19c53382d36cdba0 /src/mongo/db/query/query_request.cpp
parent90a2cb4765fe856f491e6c8215088d85e9dbb271 (diff)
downloadmongo-e7661304b820b16ad51f4485617031f9188b9229.tar.gz
SERVER-25235: singleBatch special case in QueryRequest::asAggregationCommand
When converting a QueryRequest into an aggregation command, drop the 'singleBatch' option if 'limit' is present and set to 1.
Diffstat (limited to 'src/mongo/db/query/query_request.cpp')
-rw-r--r--src/mongo/db/query/query_request.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/mongo/db/query/query_request.cpp b/src/mongo/db/query/query_request.cpp
index 9d76e502ec3..96129eb0d52 100644
--- a/src/mongo/db/query/query_request.cpp
+++ b/src/mongo/db/query/query_request.cpp
@@ -922,11 +922,6 @@ StatusWith<BSONObj> QueryRequest::asAggregationCommand() const {
return {ErrorCodes::InvalidPipelineOperator,
str::stream() << "Option " << kMaxField << " not supported in aggregation."};
}
- if (!_wantMore) {
- return {ErrorCodes::InvalidPipelineOperator,
- str::stream() << "Option " << kSingleBatchField
- << " not supported in aggregation."};
- }
if (_maxScan != 0) {
return {ErrorCodes::InvalidPipelineOperator,
str::stream() << "Option " << kMaxScanField << " not supported in aggregation."};
@@ -979,6 +974,13 @@ StatusWith<BSONObj> QueryRequest::asAggregationCommand() const {
return {ErrorCodes::BadValue,
str::stream() << "Cannot convert to an aggregation if ntoreturn is set."};
}
+ // The aggregation command normally does not support the 'singleBatch' option, but we make a
+ // special exception if 'limit' is set to 1.
+ if (!_wantMore && _limit.value_or(0) != 1LL) {
+ return {ErrorCodes::InvalidPipelineOperator,
+ str::stream() << "Option " << kSingleBatchField
+ << " not supported in aggregation."};
+ }
// Now that we've successfully validated this QR, begin building the aggregation command.
aggregationBuilder.append("aggregate", _nss.coll());