summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/index_bounds_builder_test.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2013-12-16 12:07:19 -0500
committerBenety Goh <benety@mongodb.com>2013-12-16 16:06:02 -0500
commit60a62aabd8b5301da37b05641709c12ee1b17baa (patch)
tree8274769c65c439fc85aaba1a4e06971808f9073c /src/mongo/db/query/index_bounds_builder_test.cpp
parent8ec09aaed76eb11ac9a1eb1d19e22fbf06dd9818 (diff)
downloadmongo-60a62aabd8b5301da37b05641709c12ee1b17baa.tar.gz
SERVER-12125 require fetch on $elemMatch value expressions
Diffstat (limited to 'src/mongo/db/query/index_bounds_builder_test.cpp')
-rw-r--r--src/mongo/db/query/index_bounds_builder_test.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp
index b0ae70dedf4..9bb8387d891 100644
--- a/src/mongo/db/query/index_bounds_builder_test.cpp
+++ b/src/mongo/db/query/index_bounds_builder_test.cpp
@@ -128,6 +128,31 @@ namespace {
}
}
+ //
+ // $elemMatch value
+ // Example: {a: {$elemMatch: {$gt: 2}}}
+ //
+
+ TEST(IndexBoundsBuilderTest, TranslateElemMatchValue) {
+ // Bounds generated should be the same as the embedded expression
+ // except for the tightness.
+ BSONObj obj = fromjson("{a: {$elemMatch: {$gt: 2}}}");
+ auto_ptr<MatchExpression> expr(parseMatchExpression(obj));
+ BSONElement elt = obj.firstElement();
+ OrderedIntervalList oil;
+ IndexBoundsBuilder::BoundsTightness tightness;
+ IndexBoundsBuilder::translate(expr.get(), elt, &oil, &tightness);
+ ASSERT_EQUALS(oil.name, "a");
+ ASSERT_EQUALS(oil.intervals.size(), 1U);
+ ASSERT_EQUALS(Interval::INTERVAL_EQUALS, oil.intervals[0].compare(
+ Interval(fromjson("{'': 2, '': Infinity}"), false, true)));
+ ASSERT(tightness == IndexBoundsBuilder::INEXACT_FETCH);
+ }
+
+ //
+ // Comparison operators ($lte, $lt, $gt, $gte, $eq)
+ //
+
TEST(IndexBoundsBuilderTest, TranslateLteNumber) {
BSONObj obj = fromjson("{a: {$lte: 1}}");
auto_ptr<MatchExpression> expr(parseMatchExpression(obj));