summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/parsed_update.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/ops/parsed_update.cpp')
-rw-r--r--src/mongo/db/ops/parsed_update.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/db/ops/parsed_update.cpp b/src/mongo/db/ops/parsed_update.cpp
index 07a44c54bd8..aaab7037871 100644
--- a/src/mongo/db/ops/parsed_update.cpp
+++ b/src/mongo/db/ops/parsed_update.cpp
@@ -32,6 +32,7 @@
#include "mongo/db/ops/parsed_update.h"
#include "mongo/db/ops/update_request.h"
+#include "mongo/db/ops/write_ops_gen.h"
#include "mongo/db/query/canonical_query.h"
#include "mongo/db/query/collation/collator_factory_interface.h"
#include "mongo/db/query/query_planner_common.h"
@@ -53,6 +54,22 @@ Status ParsedUpdate::parseRequest() {
// of a document during a multi-update.
invariant(!(_request->shouldReturnAnyDocs() && _request->isMulti()));
+ // It is invalid to specify 'upsertSupplied:true' for a non-upsert operation, or if no upsert
+ // document was supplied with the request.
+ if (_request->shouldUpsertSuppliedDocument()) {
+ uassert(ErrorCodes::FailedToParse,
+ str::stream() << "cannot specify '"
+ << write_ops::UpdateOpEntry::kUpsertSuppliedFieldName
+ << ": true' for a non-upsert operation",
+ _request->isUpsert());
+ const auto& constants = _request->getUpdateConstants();
+ uassert(ErrorCodes::FailedToParse,
+ str::stream() << "the parameter '"
+ << write_ops::UpdateOpEntry::kUpsertSuppliedFieldName
+ << "' is set to 'true', but no document was supplied",
+ constants && (*constants)["new"_sd].type() == BSONType::Object);
+ }
+
// It is invalid to request that a ProjectionStage be applied to the UpdateStage if the
// UpdateStage would not return any document.
invariant(_request->getProj().isEmpty() || _request->shouldReturnAnyDocs());