diff options
author | Ian Boros <puppyofkosh@gmail.com> | 2019-04-18 17:07:17 -0400 |
---|---|---|
committer | Ian Boros <puppyofkosh@gmail.com> | 2019-05-14 12:30:42 -0400 |
commit | e96d68d0c46b43c8fada1224436638a135731a38 (patch) | |
tree | 7c14b9cc98cdd50e43a63155f21324c6e8f97974 /src/mongo/db/pipeline | |
parent | cfbd6dacb7bf4b3f5b8c3cb5e4af073a33804ba7 (diff) | |
download | mongo-e96d68d0c46b43c8fada1224436638a135731a38.tar.gz |
SERVER-40134 fix bug in distinct() against views
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r-- | src/mongo/db/pipeline/field_path.h | 8 | ||||
-rw-r--r-- | src/mongo/db/pipeline/field_path_test.cpp | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/field_path.h b/src/mongo/db/pipeline/field_path.h index 0f69ebb7043..347b236fb6b 100644 --- a/src/mongo/db/pipeline/field_path.h +++ b/src/mongo/db/pipeline/field_path.h @@ -78,6 +78,14 @@ public: } /** + * Get the subpath including path elements [0, n]. + */ + StringData getSubpath(size_t n) const { + invariant(n + 1 < _fieldPathDotPosition.size()); + return StringData(_fieldPath.c_str(), _fieldPathDotPosition[n + 1]); + } + + /** * Return the ith field name from this path using zero-based indexes. */ StringData getFieldName(size_t i) const { diff --git a/src/mongo/db/pipeline/field_path_test.cpp b/src/mongo/db/pipeline/field_path_test.cpp index 999cb9b8134..b869bc38d27 100644 --- a/src/mongo/db/pipeline/field_path_test.cpp +++ b/src/mongo/db/pipeline/field_path_test.cpp @@ -188,5 +188,14 @@ TEST(FieldPathTest, ConstructorAssertsOnDeeplyNestedArrayPath) { AssertionException, ErrorCodes::Overflow); } + +// Test FieldPath::getSubpath(). +TEST(FieldPathTest, GetSubpath) { + FieldPath path = FieldPath("foo.bar.baz"); + ASSERT_EQUALS("foo", path.getSubpath(0)); + ASSERT_EQUALS("foo.bar", path.getSubpath(1)); + ASSERT_EQUALS("foo.bar.baz", path.getSubpath(2)); +} + } // namespace } // namespace mongo |