summaryrefslogtreecommitdiff
path: root/src/mongo/db/bson
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/bson
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/bson')
-rw-r--r--src/mongo/db/bson/dotted_path_support.cpp104
-rw-r--r--src/mongo/db/bson/dotted_path_support_test.cpp14
2 files changed, 52 insertions, 66 deletions
diff --git a/src/mongo/db/bson/dotted_path_support.cpp b/src/mongo/db/bson/dotted_path_support.cpp
index 256b87d1630..8bfc0483f3b 100644
--- a/src/mongo/db/bson/dotted_path_support.cpp
+++ b/src/mongo/db/bson/dotted_path_support.cpp
@@ -54,70 +54,70 @@ void _extractAllElementsAlongPath(const BSONObj& obj,
bool expandArrayOnTrailingField,
BSONDepthIndex depth,
MultikeyComponents* arrayComponents) {
- size_t idx = path.find('.');
- if (idx != std::string::npos) {
- invariant(depth != std::numeric_limits<BSONDepthIndex>::max());
- StringData left = path.substr(0, idx);
- StringData next = path.substr(idx + 1, path.size());
-
- BSONElement e = obj.getField(left);
-
- if (e.type() == Object) {
- _extractAllElementsAlongPath(e.embeddedObject(),
- next,
- elements,
- expandArrayOnTrailingField,
- depth + 1,
- arrayComponents);
- } else if (e.type() == Array) {
- bool allDigits = false;
- if (next.size() > 0 && ctype::isDigit(next[0])) {
- unsigned temp = 1;
- while (temp < next.size() && ctype::isDigit(next[temp]))
- temp++;
- allDigits = temp == next.size() || next[temp] == '.';
- }
- if (allDigits) {
+ BSONElement e = obj.getField(path);
+
+ if (e.eoo()) {
+ size_t idx = path.find('.');
+ if (idx != std::string::npos) {
+ invariant(depth != std::numeric_limits<BSONDepthIndex>::max());
+ StringData left = path.substr(0, idx);
+ StringData next = path.substr(idx + 1, path.size());
+
+ BSONElement e = obj.getField(left);
+
+ if (e.type() == Object) {
_extractAllElementsAlongPath(e.embeddedObject(),
next,
elements,
expandArrayOnTrailingField,
depth + 1,
arrayComponents);
- } else {
- BSONObjIterator i(e.embeddedObject());
- while (i.more()) {
- BSONElement e2 = i.next();
- if (e2.type() == Object || e2.type() == Array)
- _extractAllElementsAlongPath(e2.embeddedObject(),
- next,
- elements,
- expandArrayOnTrailingField,
- depth + 1,
- arrayComponents);
+ } else if (e.type() == Array) {
+ bool allDigits = false;
+ if (next.size() > 0 && ctype::isDigit(next[0])) {
+ unsigned temp = 1;
+ while (temp < next.size() && ctype::isDigit(next[temp]))
+ temp++;
+ allDigits = temp == next.size() || next[temp] == '.';
}
- if (arrayComponents) {
- arrayComponents->insert(depth);
+ if (allDigits) {
+ _extractAllElementsAlongPath(e.embeddedObject(),
+ next,
+ elements,
+ expandArrayOnTrailingField,
+ depth + 1,
+ arrayComponents);
+ } else {
+ BSONObjIterator i(e.embeddedObject());
+ while (i.more()) {
+ BSONElement e2 = i.next();
+ if (e2.type() == Object || e2.type() == Array)
+ _extractAllElementsAlongPath(e2.embeddedObject(),
+ next,
+ elements,
+ expandArrayOnTrailingField,
+ depth + 1,
+ arrayComponents);
+ }
+ if (arrayComponents) {
+ arrayComponents->insert(depth);
+ }
}
+ } else {
+ // do nothing: no match
}
- } else {
- // do nothing: no match
}
} else {
- BSONElement e = obj.getField(path);
-
- if (e.ok()) {
- if (e.type() == Array && expandArrayOnTrailingField) {
- BSONObjIterator i(e.embeddedObject());
- while (i.more()) {
- elements.insert(i.next());
- }
- if (arrayComponents) {
- arrayComponents->insert(depth);
- }
- } else {
- elements.insert(e);
+ if (e.type() == Array && expandArrayOnTrailingField) {
+ BSONObjIterator i(e.embeddedObject());
+ while (i.more()) {
+ elements.insert(i.next());
+ }
+ if (arrayComponents) {
+ arrayComponents->insert(depth);
}
+ } else {
+ elements.insert(e);
}
}
}
diff --git a/src/mongo/db/bson/dotted_path_support_test.cpp b/src/mongo/db/bson/dotted_path_support_test.cpp
index 28a2a15f433..facdf459860 100644
--- a/src/mongo/db/bson/dotted_path_support_test.cpp
+++ b/src/mongo/db/bson/dotted_path_support_test.cpp
@@ -626,19 +626,5 @@ TEST(ExtractElementAtPathOrArrayAlongPath, NumericalPathElementTreatedAsFieldNam
ASSERT(StringData(pathData).empty());
}
-TEST(ExtractElementAtPathOrArrayAlongPath, FieldWithDotsDontHideNestedObjects) {
- BSONObj obj(fromjson("{b: {c: 'foo'}, \"b.c\": 'bar'}"));
- BSONElementSet actualElements;
- const bool expandArrayOnTrailingField = true;
- MultikeyComponents actualArrayComponents;
- dps::extractAllElementsAlongPath(
- obj, "b.c", actualElements, expandArrayOnTrailingField, &actualArrayComponents);
-
- assertBSONElementSetsAreEqual({BSON("c"
- << "foo")},
- actualElements);
- assertArrayComponentsAreEqual(MultikeyComponents{}, actualArrayComponents);
-}
-
} // namespace
} // namespace mongo