summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_tree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/matcher/expression_tree.cpp')
-rw-r--r--src/mongo/db/matcher/expression_tree.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/mongo/db/matcher/expression_tree.cpp b/src/mongo/db/matcher/expression_tree.cpp
index 6b7304b024a..95e272c1cb3 100644
--- a/src/mongo/db/matcher/expression_tree.cpp
+++ b/src/mongo/db/matcher/expression_tree.cpp
@@ -30,9 +30,11 @@
#include "mongo/db/matcher/expression_tree.h"
-#include "mongo/bson/bsonobjiterator.h"
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonmisc.h"
+#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/bson/bsonobjiterator.h"
+#include "mongo/bson/bson-inl.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -54,6 +56,14 @@ namespace mongo {
_expressions[i]->debugString( debug, level + 1 );
}
+ void ListOfMatchExpression::_listToBSON(BSONArrayBuilder* out) const {
+ for ( unsigned i = 0; i < _expressions.size(); i++ ) {
+ BSONObjBuilder childBob(out->subobjStart());
+ _expressions[i]->toBSON(&childBob);
+ }
+ out->doneFast();
+ }
+
bool ListOfMatchExpression::equivalent( const MatchExpression* other ) const {
if ( matchType() != other->matchType() )
return false;
@@ -100,6 +110,11 @@ namespace mongo {
_debugList( debug, level );
}
+ void AndMatchExpression::toBSON(BSONObjBuilder* out) const {
+ BSONArrayBuilder arrBob(out->subarrayStart("$and"));
+ _listToBSON(&arrBob);
+ }
+
// -----
bool OrMatchExpression::matches( const MatchableDocument* doc, MatchDetails* details ) const {
@@ -127,6 +142,11 @@ namespace mongo {
_debugList( debug, level );
}
+ void OrMatchExpression::toBSON(BSONObjBuilder* out) const {
+ BSONArrayBuilder arrBob(out->subarrayStart("$or"));
+ _listToBSON(&arrBob);
+ }
+
// ----
bool NorMatchExpression::matches( const MatchableDocument* doc, MatchDetails* details ) const {
@@ -153,6 +173,11 @@ namespace mongo {
_debugList( debug, level );
}
+ void NorMatchExpression::toBSON(BSONObjBuilder* out) const {
+ BSONArrayBuilder arrBob(out->subarrayStart("$nor"));
+ _listToBSON(&arrBob);
+ }
+
// -------
void NotMatchExpression::debugString( StringBuilder& debug, int level ) const {
@@ -161,6 +186,12 @@ namespace mongo {
_exp->debugString( debug, level + 1 );
}
+ void NotMatchExpression::toBSON(BSONObjBuilder* out) const {
+ BSONObjBuilder childBob(out->subobjStart("$not"));
+ _exp->toBSON(&childBob);
+ childBob.doneFast();
+ }
+
bool NotMatchExpression::equivalent( const MatchExpression* other ) const {
if ( matchType() != other->matchType() )
return false;