summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_array.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/matcher/expression_array.cpp')
-rw-r--r--src/mongo/db/matcher/expression_array.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_array.cpp b/src/mongo/db/matcher/expression_array.cpp
index 9ba1c956f9a..e70175e967a 100644
--- a/src/mongo/db/matcher/expression_array.cpp
+++ b/src/mongo/db/matcher/expression_array.cpp
@@ -127,6 +127,17 @@ namespace mongo {
_sub->debugString( debug, level + 1 );
}
+ void ElemMatchObjectMatchExpression::toBSON(BSONObjBuilder* out) const {
+ BSONObjBuilder subBob;
+ _sub->toBSON(&subBob);
+ if (path().empty()) {
+ out->append("$elemMatch", subBob.obj());
+ }
+ else {
+ out->append(path(), BSON("$elemMatch" << subBob.obj()));
+ }
+ }
+
// -------
@@ -190,6 +201,19 @@ namespace mongo {
}
}
+ void ElemMatchValueMatchExpression::toBSON(BSONObjBuilder* out) const {
+ BSONObjBuilder emBob;
+ for ( unsigned i = 0; i < _subs.size(); i++ ) {
+ _subs[i]->toBSON(&emBob);
+ }
+ if (path().empty()) {
+ out->append("$elemMatch", emBob.obj());
+ }
+ else {
+ out->append(path(), BSON("$elemMatch" << emBob.obj()));
+ }
+ }
+
// ------
@@ -254,7 +278,19 @@ namespace mongo {
for ( size_t i = 0; i < _list.size(); i++ ) {
_list[i]->debugString( debug, level + 1);
}
+ }
+
+ void AllElemMatchOp::toBSON(BSONObjBuilder* out) const {
+ BSONObjBuilder allBob(out->subobjStart(path()));
+
+ BSONArrayBuilder arrBob(allBob.subarrayStart("$all"));
+ for (unsigned i = 0; i < _list.size(); i++) {
+ BSONObjBuilder childBob(arrBob.subobjStart());
+ _list[i]->toBSON(&childBob);
+ }
+ arrBob.doneFast();
+ allBob.doneFast();
}
bool AllElemMatchOp::equivalent( const MatchExpression* other ) const {
@@ -300,6 +336,10 @@ namespace mongo {
}
}
+ void SizeMatchExpression::toBSON(BSONObjBuilder* out) const {
+ out->append(path(), BSON("$size" << _size));
+ }
+
bool SizeMatchExpression::equivalent( const MatchExpression* other ) const {
if ( matchType() != other->matchType() )
return false;