diff options
author | Ian Boros <ian.boros@mongodb.com> | 2019-10-21 22:49:04 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-21 22:49:04 +0000 |
commit | 1b0927456ed31f6903cdeab64217ada8415f0c95 (patch) | |
tree | 9188241c22a047f8a2c9448b3be68e13b9871c7d /src/mongo/db/query/projection_ast.h | |
parent | 5b749ef0105d92a2a3318c01d622f25201cd7bb8 (diff) | |
download | mongo-1b0927456ed31f6903cdeab64217ada8415f0c95.tar.gz |
SERVER-42988 allow agg-style object syntax in find() projection
Diffstat (limited to 'src/mongo/db/query/projection_ast.h')
-rw-r--r-- | src/mongo/db/query/projection_ast.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/mongo/db/query/projection_ast.h b/src/mongo/db/query/projection_ast.h index 8a279fbbf8c..3f85c85c419 100644 --- a/src/mongo/db/query/projection_ast.h +++ b/src/mongo/db/query/projection_ast.h @@ -74,11 +74,16 @@ public: return _children; } + ASTNode* child(size_t index) const { + invariant(index < _children.size()); + return _children[index].get(); + } + const ASTNode* parent() const { return _parent; } - const bool isRoot() const { + bool isRoot() const { return !_parent; } @@ -156,6 +161,21 @@ public: _fieldNames.push_back(fieldName.toString()); } + /** + * Remove a node which is a direct child of this tree. Returns true if anything was removed, + * false otherwise. + */ + bool removeChild(StringData fieldName) { + if (auto it = std::find(_fieldNames.begin(), _fieldNames.end(), fieldName); + it != _fieldNames.end()) { + _children.erase(_children.begin() + std::distance(_fieldNames.begin(), it)); + _fieldNames.erase(it); + return true; + } + + return false; + } + const std::vector<std::string>& fieldNames() const { return _fieldNames; } |