summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/dependencies.cpp
diff options
context:
space:
mode:
authorIan Boros <ian.boros@mongodb.com>2019-10-24 18:51:00 +0000
committerevergreen <evergreen@mongodb.com>2019-10-24 18:51:00 +0000
commit6344b4cdc185f2e3438f3f46f35de472820f66a6 (patch)
tree2e370ad7f495426a39a57883e828a3c419a05a96 /src/mongo/db/pipeline/dependencies.cpp
parentce00713876aa3388a2abcebda00672632a0c5ff5 (diff)
downloadmongo-6344b4cdc185f2e3438f3f46f35de472820f66a6.tar.gz
SERVER-7502 test that partial projection of _id works correctly
Diffstat (limited to 'src/mongo/db/pipeline/dependencies.cpp')
-rw-r--r--src/mongo/db/pipeline/dependencies.cpp17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/mongo/db/pipeline/dependencies.cpp b/src/mongo/db/pipeline/dependencies.cpp
index 7bc9532ed6f..cfe063b976e 100644
--- a/src/mongo/db/pipeline/dependencies.cpp
+++ b/src/mongo/db/pipeline/dependencies.cpp
@@ -51,21 +51,17 @@ BSONObj DepsTracker::toProjectionWithoutMetadata() const {
return bb.obj();
}
- bool needId = false;
+ bool idSpecified = false;
std::string last;
for (const auto& field : fields) {
if (str::startsWith(field, "_id") && (field.size() == 3 || field[3] == '.')) {
- // _id and subfields are handled specially due in part to SERVER-7502
- needId = true;
- continue;
+ idSpecified = true;
}
if (!last.empty() && str::startsWith(field, last)) {
// we are including a parent of *it so we don't need to include this field
- // explicitly. In fact, due to SERVER-6527 if we included this field, the parent
- // wouldn't be fully included. This logic relies on on set iterators going in
- // lexicographic order so that a string is always directly before of all fields it
- // prefixes.
+ // explicitly. This logic relies on on set iterators going in lexicographic order so
+ // that a string is always directly before of all fields it prefixes.
continue;
}
@@ -79,10 +75,9 @@ BSONObj DepsTracker::toProjectionWithoutMetadata() const {
bb.append(field, 1);
}
- if (needId) // we are explicit either way
- bb.append("_id", 1);
- else
+ if (!idSpecified) {
bb.append("_id", 0);
+ }
return bb.obj();
}