summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/modifier_object_replace.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/ops/modifier_object_replace.cpp')
-rw-r--r--src/mongo/db/ops/modifier_object_replace.cpp22
1 files changed, 4 insertions, 18 deletions
diff --git a/src/mongo/db/ops/modifier_object_replace.cpp b/src/mongo/db/ops/modifier_object_replace.cpp
index 7b312a34a99..a7092064043 100644
--- a/src/mongo/db/ops/modifier_object_replace.cpp
+++ b/src/mongo/db/ops/modifier_object_replace.cpp
@@ -91,24 +91,6 @@ namespace mongo {
<< modExpr.type());
}
- if (opts.enforceOkForStorage) {
- Status s = modExpr.embeddedObject().storageValid();
- if (!s.isOK())
- return s;
- } else {
- // storageValid checks for $-prefixed field names, so only run if we didn't do that.
- BSONObjIterator it(modExpr.embeddedObject());
- while (it.more()) {
- BSONElement elem = it.next();
- if (*elem.fieldName() == '$') {
- return Status(ErrorCodes::BadValue,
- str::stream() << "A replace document can't"
- " contain update modifiers: "
- << elem.fieldNameStringData());
- }
- }
- }
-
// We make a copy of the object here because the update driver does not guarantees, in
// the case of object replacement, that the modExpr is going to outlive this mod.
_val = modExpr.embeddedObject().getOwned();
@@ -165,6 +147,10 @@ namespace mongo {
// Do not duplicate _id field
if (srcIdElement.ok()) {
+ if (srcIdElement.compareWithBSONElement(dstIdElement, true) != 0) {
+ return Status(ErrorCodes::ImmutableField,
+ "The _id field cannot be changed.");
+ }
continue;
}
}