summaryrefslogtreecommitdiff
path: root/db/queryutil.h
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-06-09 14:43:36 -0700
committerAaron <aaron@10gen.com>2010-06-09 14:43:36 -0700
commiteabc79c785d7687af057b4d0dd3ee657fa32760d (patch)
treeb202f081cbe89704ff6f33550fcdae7f99683053 /db/queryutil.h
parenta18d67076188ae7288d993a6581daea444ac1cf3 (diff)
downloadmongo-eabc79c785d7687af057b4d0dd3ee657fa32760d.tar.gz
SERVER-109 expand $in clauses in simplifiedQuery
Diffstat (limited to 'db/queryutil.h')
-rw-r--r--db/queryutil.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/db/queryutil.h b/db/queryutil.h
index 10235644589..5b680d81aa6 100644
--- a/db/queryutil.h
+++ b/db/queryutil.h
@@ -80,7 +80,21 @@ namespace mongo {
i->_lower._inclusive = false;
i->_upper._inclusive = false;
}
- }
+ }
+ // if cannot construct an $in query, BSONObj() is returned
+ BSONObj simplifiedIn() const {
+ BSONObjBuilder b;
+ BSONArrayBuilder a( b.subarrayStart("$in") );
+ for( vector< FieldInterval >::const_iterator i = _intervals.begin(); i != _intervals.end(); ++i ) {
+ if ( !i->_upper._inclusive || !i->_lower._inclusive ||
+ i->_upper._bound.woCompare( i->_lower._bound, false ) != 0 ) {
+ return BSONObj();
+ }
+ a << i->_upper._bound;
+ }
+ a.done();
+ return b.obj();
+ }
private:
BSONObj addObj( const BSONObj &o );
void finishOperation( const vector< FieldInterval > &newIntervals, const FieldRange &other );
@@ -191,7 +205,7 @@ namespace mongo {
}
const char *ns() const { return _ns; }
// if fields is specified, order fields of returned object to match those of 'fields'
- BSONObj simplifiedQuery( const BSONObj &fields = BSONObj() ) const;
+ BSONObj simplifiedQuery( const BSONObj &fields = BSONObj(), bool expandIn = false ) const;
bool matchPossible() const {
for( map< string, FieldRange >::const_iterator i = _ranges.begin(); i != _ranges.end(); ++i )
if ( i->second.empty() )