diff options
Diffstat (limited to 'src/mongo/db/pipeline/document_source_change_stream_transform.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/document_source_change_stream_transform.cpp | 115 |
1 files changed, 9 insertions, 106 deletions
diff --git a/src/mongo/db/pipeline/document_source_change_stream_transform.cpp b/src/mongo/db/pipeline/document_source_change_stream_transform.cpp index 9e5bd9ecaa6..766150a6e54 100644 --- a/src/mongo/db/pipeline/document_source_change_stream_transform.cpp +++ b/src/mongo/db/pipeline/document_source_change_stream_transform.cpp @@ -33,7 +33,6 @@ #include "mongo/db/pipeline/document_source_change_stream_transform.h" -#include "mongo/db/pipeline/change_stream_helpers.h" #include "mongo/db/pipeline/expression.h" #include "mongo/db/pipeline/lite_parsed_document_source.h" #include "mongo/db/pipeline/resume_token.h" @@ -64,10 +63,6 @@ DocumentSourceChangeStreamTransform::createFromBson( rawSpec.type() == BSONType::Object); auto spec = DocumentSourceChangeStreamSpec::parse(IDLParserErrorContext("$changeStream"), rawSpec.Obj()); - - // Set the change stream spec on the expression context. - expCtx->changeStreamSpec = spec; - return new DocumentSourceChangeStreamTransform(expCtx, std::move(spec)); } @@ -79,7 +74,8 @@ DocumentSourceChangeStreamTransform::DocumentSourceChangeStreamTransform( _isIndependentOfAnyCollection(expCtx->ns.isCollectionlessAggregateNS()) { // Extract the resume token or high-water-mark from the spec. - auto tokenData = change_stream::resolveResumeTokenFromSpec(expCtx, _changeStreamSpec); + auto tokenData = + DocumentSourceChangeStream::resolveResumeTokenFromSpec(expCtx, _changeStreamSpec); // Set the initialPostBatchResumeToken on the expression context. expCtx->initialPostBatchResumeToken = ResumeToken(tokenData).toBSON(); @@ -103,109 +99,16 @@ StageConstraints DocumentSourceChangeStreamTransform::constraints( return constraints; } -namespace { - -template <typename T> -void serializeSpecField(BSONObjBuilder* builder, - const SerializationOptions& opts, - const StringData& fieldName, - const boost::optional<T>& value) { - if (value) { - opts.serializeLiteral((*value).toBSON()).addToBsonObj(builder, fieldName); - } -} - -template <> -void serializeSpecField(BSONObjBuilder* builder, - const SerializationOptions& opts, - const StringData& fieldName, - const boost::optional<Timestamp>& value) { - if (value) { - opts.serializeLiteral(*value).addToBsonObj(builder, fieldName); - } -} - -template <typename T> -void serializeSpecField(BSONObjBuilder* builder, - const SerializationOptions& opts, - const StringData& fieldName, - const T& value) { - opts.appendLiteral(builder, fieldName, value); -} - -template <> -void serializeSpecField(BSONObjBuilder* builder, - const SerializationOptions& opts, - const StringData& fieldName, - const mongo::OptionalBool& value) { - if (value.has_value()) { - opts.appendLiteral(builder, fieldName, value.value_or(true)); - } -} - -void serializeSpec(const DocumentSourceChangeStreamSpec& spec, - const SerializationOptions& opts, - BSONObjBuilder* builder) { - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kResumeAfterFieldName, - spec.getResumeAfter()); - serializeSpecField( - builder, opts, DocumentSourceChangeStreamSpec::kStartAfterFieldName, spec.getStartAfter()); - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kStartAtOperationTimeFieldName, - spec.getStartAtOperationTime()); - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kFullDocumentFieldName, - ::mongo::FullDocumentMode_serializer(spec.getFullDocument())); - serializeSpecField( - builder, - opts, - DocumentSourceChangeStreamSpec::kFullDocumentBeforeChangeFieldName, - ::mongo::FullDocumentBeforeChangeMode_serializer(spec.getFullDocumentBeforeChange())); - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kAllChangesForClusterFieldName, - spec.getAllChangesForCluster()); - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kShowMigrationEventsFieldName, - spec.getShowMigrationEvents()); - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kShowSystemEventsFieldName, - spec.getShowSystemEvents()); - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kAllowToRunOnConfigDBFieldName, - spec.getAllowToRunOnConfigDB()); - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kAllowToRunOnSystemNSFieldName, - spec.getAllowToRunOnSystemNS()); - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kShowExpandedEventsFieldName, - spec.getShowExpandedEvents()); - serializeSpecField(builder, - opts, - DocumentSourceChangeStreamSpec::kShowRawUpdateDescriptionFieldName, - spec.getShowRawUpdateDescription()); -} - -} // namespace - -Value DocumentSourceChangeStreamTransform::serialize(const SerializationOptions& opts) const { - if (opts.verbosity) { +Value DocumentSourceChangeStreamTransform::serialize( + boost::optional<ExplainOptions::Verbosity> explain) const { + if (explain) { return Value(Document{{DocumentSourceChangeStream::kStageName, Document{{"stage"_sd, "internalTransform"_sd}, - {"options"_sd, _changeStreamSpec.toBSON(opts)}}}}); + {"options"_sd, _changeStreamSpec.toBSON()}}}}); } - return Value(Document{ - {DocumentSourceChangeStreamTransform::kStageName, _changeStreamSpec.toBSON(opts)}}); + return Value( + Document{{DocumentSourceChangeStreamTransform::kStageName, _changeStreamSpec.toBSON()}}); } DepsTracker::State DocumentSourceChangeStreamTransform::getDependencies(DepsTracker* deps) const { @@ -215,7 +118,7 @@ DepsTracker::State DocumentSourceChangeStreamTransform::getDependencies(DepsTrac DocumentSource::GetModPathsReturn DocumentSourceChangeStreamTransform::getModifiedPaths() const { // All paths are modified. - return {DocumentSource::GetModPathsReturn::Type::kAllPaths, OrderedPathSet{}, {}}; + return {DocumentSource::GetModPathsReturn::Type::kAllPaths, std::set<std::string>{}, {}}; } DocumentSource::GetNextResult DocumentSourceChangeStreamTransform::doGetNext() { |
