summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2021-09-09 15:45:17 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-20 23:22:54 +0000
commitf17d70733a710dee5aebb3807046bba6a23defdf (patch)
tree06c0714d9edeccd9fcb81424f9e0ff94b90fa9fa /src/mongo
parent2aab634ab141f0dce9c35d9805d213518cc4690a (diff)
downloadmongo-f17d70733a710dee5aebb3807046bba6a23defdf.tar.gz
SERVER-58777 Do not count empty subdocuments toward depth on insert
(cherry picked from commit 266fbb8024d99be7d288ae7da609b67884473396)
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/ops/insert.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/mongo/db/ops/insert.cpp b/src/mongo/db/ops/insert.cpp
index 88da6945aa5..74e69ba4e7e 100644
--- a/src/mongo/db/ops/insert.cpp
+++ b/src/mongo/db/ops/insert.cpp
@@ -56,7 +56,10 @@ Status validateDepth(const BSONObj& obj) {
while (!frames.empty()) {
const auto elem = frames.back().next();
if (elem.type() == BSONType::Object || elem.type() == BSONType::Array) {
- if (MONGO_unlikely(frames.size() == BSONDepth::getMaxDepthForUserStorage())) {
+ auto subObj = elem.embeddedObject();
+ // Empty subdocuments do not count toward the depth of a document.
+ if (MONGO_unlikely(frames.size() == BSONDepth::getMaxDepthForUserStorage() &&
+ !subObj.isEmpty())) {
// We're exactly at the limit, so descending to the next level would exceed
// the maximum depth.
return {ErrorCodes::Overflow,
@@ -64,7 +67,7 @@ Status validateDepth(const BSONObj& obj) {
<< "cannot insert document because it exceeds "
<< BSONDepth::getMaxDepthForUserStorage() << " levels of nesting"};
}
- frames.emplace_back(elem.embeddedObject());
+ frames.emplace_back(subObj);
}
if (!frames.back().more()) {