diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-12-04 01:25:50 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-12-04 01:25:50 -0500 |
commit | 2aec9ea61d05cb17a1b52e3198d40a7c74b81572 (patch) | |
tree | 38d48ae0f6240e495f1f1b5ac2b0d48ef7b4ebf4 /db/dbhelpers.cpp | |
parent | f4d7fb2854762af8547746a564a0b37bf006bf3a (diff) | |
download | mongo-2aec9ea61d05cb17a1b52e3198d40a7c74b81572.tar.gz |
moving towards direct access from DBDirectClient rather than through message layer
not finished
Diffstat (limited to 'db/dbhelpers.cpp')
-rw-r--r-- | db/dbhelpers.cpp | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/db/dbhelpers.cpp b/db/dbhelpers.cpp index 0671aa0368a..64cab3b8efb 100644 --- a/db/dbhelpers.cpp +++ b/db/dbhelpers.cpp @@ -27,6 +27,48 @@ namespace mongo { + CursorIterator::CursorIterator( auto_ptr<Cursor> c , BSONObj filter ) + : _cursor( c ){ + if ( filter.isEmpty() ) + _matcher = 0; + else + _matcher = new KeyValJSMatcher( filter , BSONObj() ); + _advance(); + } + + CursorIterator::~CursorIterator(){ + if ( _matcher ){ + delete _matcher; + _matcher = 0; + } + } + + BSONObj CursorIterator::next(){ + BSONObj o = _o; + _advance(); + return o; + } + + bool CursorIterator::hasNext(){ + return ! _o.isEmpty(); + } + + void CursorIterator::_advance(){ + if ( ! _cursor->ok() ){ + _o = BSONObj(); + return; + } + + while ( _cursor->ok() ){ + _o = _cursor->current(); + _cursor->advance(); + if ( _matcher == 0 || _matcher->matches( _o ) ) + return; + } + + _o = BSONObj(); + } + void Helpers::ensureIndex(const char *ns, BSONObj keyPattern, bool unique, const char *name) { NamespaceDetails *d = nsdetails(ns); if( d == 0 ) @@ -107,9 +149,8 @@ namespace mongo { auto_ptr<CursorIterator> Helpers::find( const char *ns , BSONObj query , bool requireIndex ){ uassert( "requireIndex not supported in Helpers::find yet" , ! requireIndex ); - uassert( "queries not allowed on Helpers::find yet" , query.isEmpty() ); auto_ptr<CursorIterator> i; - i.reset( new CursorIterator( DataFileMgr::findAll( ns ) ) ); + i.reset( new CursorIterator( DataFileMgr::findAll( ns ) , query ) ); return i; } |