diff options
Diffstat (limited to 'src/mongo/db/query/parsed_distinct.cpp')
-rw-r--r-- | src/mongo/db/query/parsed_distinct.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/mongo/db/query/parsed_distinct.cpp b/src/mongo/db/query/parsed_distinct.cpp index 3c3a75c62cd..8b024533326 100644 --- a/src/mongo/db/query/parsed_distinct.cpp +++ b/src/mongo/db/query/parsed_distinct.cpp @@ -42,6 +42,7 @@ namespace mongo { const char ParsedDistinct::kKeyField[] = "key"; const char ParsedDistinct::kQueryField[] = "query"; const char ParsedDistinct::kCollationField[] = "collation"; +const char ParsedDistinct::kCommentField[] = "comment"; StatusWith<BSONObj> ParsedDistinct::asAggregationCommand() const { BSONObjBuilder aggregationBuilder; @@ -88,6 +89,23 @@ StatusWith<BSONObj> ParsedDistinct::asAggregationCommand() const { aggregationBuilder.append(kCollationField, qr.getCollation()); + if (qr.getMaxTimeMS() > 0) { + aggregationBuilder.append(QueryRequest::cmdOptionMaxTimeMS, qr.getMaxTimeMS()); + } + + if (!qr.getReadConcern().isEmpty()) { + aggregationBuilder.append(repl::ReadConcernArgs::kReadConcernFieldName, + qr.getReadConcern()); + } + + if (!qr.getUnwrappedReadPref().isEmpty()) { + aggregationBuilder.append(QueryRequest::kUnwrappedReadPrefField, qr.getUnwrappedReadPref()); + } + + if (!qr.getComment().empty()) { + aggregationBuilder.append(kCommentField, qr.getComment()); + } + // Specify the 'cursor' option so that aggregation uses the cursor interface. aggregationBuilder.append("cursor", BSONObj()); @@ -137,6 +155,50 @@ StatusWith<ParsedDistinct> ParsedDistinct::parse(OperationContext* opCtx, qr->setCollation(collationElt.embeddedObject()); } + if (BSONElement readConcernElt = cmdObj[repl::ReadConcernArgs::kReadConcernFieldName]) { + if (readConcernElt.type() != BSONType::Object) { + return Status(ErrorCodes::TypeMismatch, + str::stream() << "\"" << repl::ReadConcernArgs::kReadConcernFieldName + << "\" had the wrong type. Expected " + << typeName(BSONType::Object) + << ", found " + << typeName(readConcernElt.type())); + } + qr->setReadConcern(readConcernElt.embeddedObject()); + } + + if (BSONElement commentElt = cmdObj[kCommentField]) { + if (commentElt.type() != BSONType::String) { + return Status(ErrorCodes::TypeMismatch, + str::stream() << "\"" << kCommentField + << "\" had the wrong type. Expected " + << typeName(BSONType::String) + << ", found " + << typeName(commentElt.type())); + } + qr->setComment(commentElt.str()); + } + + if (BSONElement queryOptionsElt = cmdObj[QueryRequest::kUnwrappedReadPrefField]) { + if (queryOptionsElt.type() != BSONType::Object) { + return Status(ErrorCodes::TypeMismatch, + str::stream() << "\"" << QueryRequest::kUnwrappedReadPrefField + << "\" had the wrong type. Expected " + << typeName(BSONType::Object) + << ", found " + << typeName(queryOptionsElt.type())); + } + qr->setUnwrappedReadPref(queryOptionsElt.embeddedObject()); + } + + if (BSONElement maxTimeMSElt = cmdObj[QueryRequest::cmdOptionMaxTimeMS]) { + auto maxTimeMS = QueryRequest::parseMaxTimeMS(maxTimeMSElt); + if (!maxTimeMS.isOK()) { + return maxTimeMS.getStatus(); + } + qr->setMaxTimeMS(static_cast<unsigned int>(maxTimeMS.getValue())); + } + qr->setExplain(isExplain); auto cq = CanonicalQuery::canonicalize(opCtx, std::move(qr), extensionsCallback); |