diff options
author | Sally McNichols <sally.mcnichols@mongodb.com> | 2016-08-04 16:37:32 -0400 |
---|---|---|
committer | Sally McNichols <sally.mcnichols@mongodb.com> | 2016-08-04 16:37:32 -0400 |
commit | 1f291f5be44a18bd578b9a2402715531ed5d0a67 (patch) | |
tree | 5c02a5d880a949f2e57600c8a618c5a07e660778 /src/mongo/db/pipeline/parsed_aggregation_projection.cpp | |
parent | 215d900368abcb5ea05daeadb889cd380122d312 (diff) | |
download | mongo-1f291f5be44a18bd578b9a2402715531ed5d0a67.tar.gz |
SERVER-24921 allow excluding only the _id field in $project
Diffstat (limited to 'src/mongo/db/pipeline/parsed_aggregation_projection.cpp')
-rw-r--r-- | src/mongo/db/pipeline/parsed_aggregation_projection.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/parsed_aggregation_projection.cpp b/src/mongo/db/pipeline/parsed_aggregation_projection.cpp index c51c3be8548..2beceb4889e 100644 --- a/src/mongo/db/pipeline/parsed_aggregation_projection.cpp +++ b/src/mongo/db/pipeline/parsed_aggregation_projection.cpp @@ -100,8 +100,19 @@ private: void parse() { uassert(40177, "$project specification must have at least one field", !_rawObj.isEmpty()); + size_t nFields = 0; for (auto&& elem : _rawObj) { parseElement(elem, FieldPath(elem.fieldName())); + nFields++; + } + + // Check for the case where we only exclude '_id'. + if (nFields == 1) { + BSONElement elem = _rawObj.firstElement(); + if (elem.fieldNameStringData() == "_id" && (elem.isBoolean() || elem.isNumber()) && + !elem.trueValue()) { + _parsedType = ProjectionType::kExclusion; + } } // Default to inclusion if nothing (except maybe '_id') is explicitly included or excluded. |