diff options
author | Ted Tuckman <ted.tuckman@mongodb.com> | 2019-11-15 19:50:52 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-15 19:50:52 +0000 |
commit | 6258369bc2d74e69a5e1fd8e025a291550aeb368 (patch) | |
tree | be895955944d025eb4dd94f1771ef883cb3515cc /src/mongo/db/pipeline/document_source_out.h | |
parent | ab0e1e6875faa56155eb4777be66b575f6b48395 (diff) | |
download | mongo-6258369bc2d74e69a5e1fd8e025a291550aeb368.tar.gz |
SERVER-42693 Add renameAndPreserveOptions command and allow $out to output to different DB
Diffstat (limited to 'src/mongo/db/pipeline/document_source_out.h')
-rw-r--r-- | src/mongo/db/pipeline/document_source_out.h | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/mongo/db/pipeline/document_source_out.h b/src/mongo/db/pipeline/document_source_out.h index 28241d82893..971f1652c47 100644 --- a/src/mongo/db/pipeline/document_source_out.h +++ b/src/mongo/db/pipeline/document_source_out.h @@ -38,6 +38,7 @@ namespace mongo { class DocumentSourceOut final : public DocumentSourceWriter<BSONObj> { public: static constexpr StringData kStageName = "$out"_sd; + static constexpr StringData kInternalStageName = "$internalOutToDifferentDB"_sd; /** * A "lite parsed" $out stage is similar to other stages involving foreign collections except in @@ -51,6 +52,9 @@ public: static std::unique_ptr<LiteParsed> parse(const AggregationRequest& request, const BSONElement& spec); + static std::unique_ptr<LiteParsed> parseToDifferentDB(const AggregationRequest& request, + const BSONElement& spec); + bool allowShardedForeignCollection(NamespaceString nss) const final { return _foreignNssSet.find(nss) == _foreignNssSet.end(); } @@ -63,6 +67,9 @@ public: ~DocumentSourceOut() override; const char* getSourceName() const final override { + if (_toDifferentDB) { + return kInternalStageName.rawData(); + } return kStageName.rawData(); } @@ -80,21 +87,30 @@ public: boost::optional<ExplainOptions::Verbosity> explain = boost::none) const final override; /** - * Creates a new $out stage from the given arguments. + * Creates a new $out or $internalOutToDifferentDB stage from the given arguments. */ static boost::intrusive_ptr<DocumentSource> create( NamespaceString outputNs, const boost::intrusive_ptr<ExpressionContext>& expCtx); + static boost::intrusive_ptr<DocumentSource> createAndAllowDifferentDB( + NamespaceString outputNs, const boost::intrusive_ptr<ExpressionContext>& expCtx); + /** - * Parses a $out stage from the user-supplied BSON. + * Parses a $out or $internalOutToDifferentDB stage from the user-supplied BSON. */ static boost::intrusive_ptr<DocumentSource> createFromBson( BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& pExpCtx); + static boost::intrusive_ptr<DocumentSource> createFromBsonToDifferentDB( + BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& pExpCtx); private: DocumentSourceOut(NamespaceString outputNs, const boost::intrusive_ptr<ExpressionContext>& expCtx) - : DocumentSourceWriter(kStageName.rawData(), std::move(outputNs), expCtx) {} + : DocumentSourceWriter(outputNs.db() == expCtx->ns.db() ? kStageName.rawData() + : kInternalStageName.rawData(), + std::move(outputNs), + expCtx), + _toDifferentDB(getOutputNs().db() != expCtx->ns.db()) {} void initialize() override; @@ -122,6 +138,10 @@ private: // The temporary namespace for the $out writes. NamespaceString _tempNs; + + // Keep track of whether this document source is writing to a different DB for serialization + // purposes. + bool _toDifferentDB; }; } // namespace mongo |