diff options
Diffstat (limited to 'src/mongo/db/pipeline/pipeline.cpp')
-rw-r--r-- | src/mongo/db/pipeline/pipeline.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/pipeline.cpp b/src/mongo/db/pipeline/pipeline.cpp index eb3a4d97914..ce3e9e89fa4 100644 --- a/src/mongo/db/pipeline/pipeline.cpp +++ b/src/mongo/db/pipeline/pipeline.cpp @@ -148,6 +148,24 @@ Pipeline::~Pipeline() { invariant(_disposed); } +std::unique_ptr<Pipeline, PipelineDeleter> Pipeline::clone() const { + const auto& serialized = serialize(); + std::vector<BSONObj> asBson; + asBson.reserve(serialized.size()); + for (auto&& stage : serialized) { + invariant(stage.getType() == BSONType::Object); + asBson.push_back(stage.getDocument().toBson()); + } + try { + return parse(asBson, getContext()); + } catch (DBException& ex) { + ex.addContext(str::stream() + << "Failed to copy pipeline. Could not parse serialized version: " + << Value(serialized).toString()); + throw; + } +} + std::unique_ptr<Pipeline, PipelineDeleter> Pipeline::parse( const std::vector<BSONObj>& rawPipeline, const intrusive_ptr<ExpressionContext>& expCtx, |