summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_change_notification.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/document_source_change_notification.h')
-rw-r--r--src/mongo/db/pipeline/document_source_change_notification.h48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/mongo/db/pipeline/document_source_change_notification.h b/src/mongo/db/pipeline/document_source_change_notification.h
index 3b38a908626..ad10a5ad210 100644
--- a/src/mongo/db/pipeline/document_source_change_notification.h
+++ b/src/mongo/db/pipeline/document_source_change_notification.h
@@ -51,6 +51,8 @@ public:
}
stdx::unordered_set<NamespaceString> getInvolvedNamespaces() const final {
+ // TODO SERVER-29138: we need to communicate that this stage will need to look up
+ // documents from different collections.
return stdx::unordered_set<NamespaceString>();
}
@@ -62,6 +64,8 @@ public:
class Transformation : public DocumentSourceSingleDocumentTransformation::TransformerInterface {
public:
+ Transformation(BSONObj changeNotificationSpec)
+ : _changeNotificationSpec(changeNotificationSpec.getOwned()) {}
~Transformation() = default;
Document applyTransformation(const Document& input) final;
TransformerType getType() const final {
@@ -72,10 +76,48 @@ public:
boost::optional<ExplainOptions::Verbosity> explain) const final;
DocumentSource::GetDepsReturn addDependencies(DepsTracker* deps) const final;
DocumentSource::GetModPathsReturn getModifiedPaths() const final;
+
+ private:
+ BSONObj _changeNotificationSpec;
};
+ // The name of the field where the document key (_id and shard key, if present) will be found
+ // after the transformation.
+ static constexpr StringData kDocumentKeyField = "documentKey"_sd;
+
+ // The name of the field where the full document will be found after the transformation. The
+ // full document is only present for certain types of operations, such as an insert.
+ static constexpr StringData kFullDocumentField = "fullDocument"_sd;
+
+ // The name of the field where the change identifier will be located after the transformation.
+ static constexpr StringData kIdField = "_id"_sd;
+
+ // The name of the field where the namespace of the change will be located after the
+ // transformation.
+ static constexpr StringData kNamespaceField = "ns"_sd;
+
+ // The name of the field where the type of the operation will be located after the
+ // transformation.
+ static constexpr StringData kOperationTypeField = "operationType"_sd;
+
+ // The name of this stage.
+ static constexpr StringData kStageName = "$changeNotification"_sd;
+
+ // The name of the field where the timestamp of the change will be located after the
+ // transformation. The timestamp will be located inside the change identifier, so the full path
+ // to the timestamp will be kIdField + "." + kTimestampField.
+ static constexpr StringData kTimestmapField = "ts"_sd;
+
+ // The different types of operations we can use for the operation type.
+ static constexpr StringData kUpdateOpType = "update"_sd;
+ static constexpr StringData kDeleteOpType = "delete"_sd;
+ static constexpr StringData kReplaceOpType = "replace"_sd;
+ static constexpr StringData kInsertOpType = "insert"_sd;
+ static constexpr StringData kInvalidateOpType = "invalidate"_sd;
+
/**
- * Produce the BSON for the $match stage based on a $changeNotification stage.
+ * Produce the BSON object representing the filter for the $match stage to filter oplog entries
+ * to only those relevant for this $changeNotification stage.
*/
static BSONObj buildMatchFilter(const NamespaceString& nss);
@@ -83,11 +125,11 @@ public:
* Parses a $changeNotification stage from 'elem' and produces the $match and transformation
* stages required.
*/
- static std::vector<boost::intrusive_ptr<DocumentSource>> createFromBson(
+ static std::list<boost::intrusive_ptr<DocumentSource>> createFromBson(
BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& expCtx);
static boost::intrusive_ptr<DocumentSource> createTransformationStage(
- const boost::intrusive_ptr<ExpressionContext>& pExpCtx);
+ BSONObj changeNotificationSpec, const boost::intrusive_ptr<ExpressionContext>& pExpCtx);
private:
// It is illegal to construct a DocumentSourceChangeNotification directly, use createFromBson()