summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcsum112 <catalin.sumanaru@mongodb.com>2022-07-05 13:13:07 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-05 13:50:02 +0000
commit91a4179916a8627f8e492a2a6e26dc4679033842 (patch)
treea8b5d32c26d9e6c99baa8c15e8ae5bb76e0937b8
parentd7f5e06a9e82e57852260267b1b5674937728e4d (diff)
downloadmongo-91a4179916a8627f8e492a2a6e26dc4679033842.tar.gz
SERVER-66808 Remove undocumented fields from the change stream error
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream_add_post_image.cpp13
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream_add_pre_image.cpp13
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream_add_pre_image.h3
3 files changed, 21 insertions, 8 deletions
diff --git a/src/mongo/db/pipeline/document_source_change_stream_add_post_image.cpp b/src/mongo/db/pipeline/document_source_change_stream_add_post_image.cpp
index ab3f95abca1..822e41f3352 100644
--- a/src/mongo/db/pipeline/document_source_change_stream_add_post_image.cpp
+++ b/src/mongo/db/pipeline/document_source_change_stream_add_post_image.cpp
@@ -48,6 +48,8 @@ REGISTER_INTERNAL_DOCUMENT_SOURCE(_internalChangeStreamAddPostImage,
DocumentSourceChangeStreamAddPostImage::createFromBson,
true);
+constexpr auto makePostImageNotFoundErrorMsg =
+ &DocumentSourceChangeStreamAddPreImage::makePreImageNotFoundErrorMsg;
Value assertFieldHasType(const Document& fullDoc, StringData fieldName, BSONType expectedType) {
auto val = fullDoc[fieldName];
@@ -97,12 +99,11 @@ DocumentSource::GetNextResult DocumentSourceChangeStreamAddPostImage::doGetNext(
const auto postImageDoc = (_fullDocumentMode == FullDocumentModeEnum::kUpdateLookup
? lookupLatestPostImage(output.peek())
: generatePostImage(output.peek()));
- uassert(
- ErrorCodes::NoMatchingDocument,
- str::stream() << "Change stream was configured to require a post-image for all update, "
- "delete and replace events, but the post-image was not found for event: "
- << output.peek().toString(),
- postImageDoc || _fullDocumentMode != FullDocumentModeEnum::kRequired);
+ uassert(ErrorCodes::NoMatchingDocument,
+ str::stream() << "Change stream was configured to require a post-image for all update "
+ "events, but the post-image was not found for event: "
+ << makePostImageNotFoundErrorMsg(output.peek()),
+ postImageDoc || _fullDocumentMode != FullDocumentModeEnum::kRequired);
// Even if no post-image was found, we have to populate the 'fullDocument' field.
output[kFullDocumentFieldName] = (postImageDoc ? Value(*postImageDoc) : Value(BSONNULL));
diff --git a/src/mongo/db/pipeline/document_source_change_stream_add_pre_image.cpp b/src/mongo/db/pipeline/document_source_change_stream_add_pre_image.cpp
index 6b37f50f723..aca01dda4d3 100644
--- a/src/mongo/db/pipeline/document_source_change_stream_add_pre_image.cpp
+++ b/src/mongo/db/pipeline/document_source_change_stream_add_pre_image.cpp
@@ -99,7 +99,7 @@ DocumentSource::GetNextResult DocumentSourceChangeStreamAddPreImage::doGetNext()
str::stream()
<< "Change stream was configured to require a pre-image for all update, delete "
"and replace events, but pre-image id was not available for event: "
- << input.getDocument().toString(),
+ << makePreImageNotFoundErrorMsg(input.getDocument()),
_fullDocumentBeforeChangeMode != FullDocumentBeforeChangeModeEnum::kRequired);
return input;
}
@@ -113,7 +113,7 @@ DocumentSource::GetNextResult DocumentSourceChangeStreamAddPreImage::doGetNext()
ErrorCodes::NoMatchingDocument,
str::stream() << "Change stream was configured to require a pre-image for all update, "
"delete and replace events, but the pre-image was not found for event: "
- << input.getDocument().toString(),
+ << makePreImageNotFoundErrorMsg(input.getDocument()),
preImageDoc ||
_fullDocumentBeforeChangeMode != FullDocumentBeforeChangeModeEnum::kRequired);
@@ -167,4 +167,13 @@ Value DocumentSourceChangeStreamAddPreImage::serialize(
DocumentSourceChangeStreamAddPreImageSpec(_fullDocumentBeforeChangeMode).toBSON()}});
}
+std::string DocumentSourceChangeStreamAddPreImage::makePreImageNotFoundErrorMsg(
+ const Document& event) {
+ auto errMsgDoc = Document{{"operationType", event["operationType"]},
+ {"ns", event["ns"]},
+ {"clusterTime", event["clusterTime"]},
+ {"txnNumber", event["txnNumber"]}};
+ return errMsgDoc.toString();
+}
+
} // namespace mongo
diff --git a/src/mongo/db/pipeline/document_source_change_stream_add_pre_image.h b/src/mongo/db/pipeline/document_source_change_stream_add_pre_image.h
index cc735fc135e..e04ac9a30ef 100644
--- a/src/mongo/db/pipeline/document_source_change_stream_add_pre_image.h
+++ b/src/mongo/db/pipeline/document_source_change_stream_add_pre_image.h
@@ -63,6 +63,9 @@ public:
static boost::optional<Document> lookupPreImage(boost::intrusive_ptr<ExpressionContext> pExpCtx,
const Document& preImageId);
+ // Removes the internal fields from the event and returns the string representation of it.
+ static std::string makePreImageNotFoundErrorMsg(const Document& event);
+
DocumentSourceChangeStreamAddPreImage(const boost::intrusive_ptr<ExpressionContext>& expCtx,
FullDocumentBeforeChangeModeEnum mode)
: DocumentSource(kStageName, expCtx), _fullDocumentBeforeChangeMode(mode) {