summaryrefslogtreecommitdiff
path: root/db/commands/distinct.cpp
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2011-09-14 17:08:06 +0200
committerAntonin Kral <a.kral@bobek.cz>2011-09-14 17:08:06 +0200
commit5d342a758c6095b4d30aba0750b54f13b8916f51 (patch)
tree762e9aa84781f5e3b96db2c02d356c29cf0217c0 /db/commands/distinct.cpp
parentcbe2d992e9cd1ea66af9fa91df006106775d3073 (diff)
downloadmongodb-5d342a758c6095b4d30aba0750b54f13b8916f51.tar.gz
Imported Upstream version 2.0.0
Diffstat (limited to 'db/commands/distinct.cpp')
-rw-r--r--db/commands/distinct.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/db/commands/distinct.cpp b/db/commands/distinct.cpp
index 7b2f6a8..48f4405 100644
--- a/db/commands/distinct.cpp
+++ b/db/commands/distinct.cpp
@@ -32,7 +32,7 @@ namespace mongo {
help << "{ distinct : 'collection name' , key : 'a.b' , query : {} }";
}
- bool run(const string& dbname, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
+ bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
Timer t;
string ns = dbname + '.' + cmdObj.firstElement().valuestr();
@@ -63,7 +63,7 @@ namespace mongo {
shared_ptr<Cursor> cursor;
if ( ! query.isEmpty() ) {
- cursor = bestGuessCursor(ns.c_str() , query , BSONObj() );
+ cursor = NamespaceDetailsTransient::getCursor(ns.c_str() , query , BSONObj() );
}
else {
@@ -78,29 +78,33 @@ namespace mongo {
if ( idx.inKeyPattern( key ) ) {
cursor = bestGuessCursor( ns.c_str() , BSONObj() , idx.keyPattern() );
- break;
+ if( cursor.get() ) break;
}
}
if ( ! cursor.get() )
- cursor = bestGuessCursor(ns.c_str() , query , BSONObj() );
+ cursor = NamespaceDetailsTransient::getCursor(ns.c_str() , query , BSONObj() );
}
-
-
- scoped_ptr<ClientCursor> cc (new ClientCursor(QueryOption_NoCursorTimeout, cursor, ns));
+
+ assert( cursor );
+ string cursorName = cursor->toString();
+
+ auto_ptr<ClientCursor> cc (new ClientCursor(QueryOption_NoCursorTimeout, cursor, ns));
while ( cursor->ok() ) {
nscanned++;
bool loadedObject = false;
- if ( !cursor->matcher() || cursor->matcher()->matchesCurrent( cursor.get() , &md ) ) {
+ if ( ( !cursor->matcher() || cursor->matcher()->matchesCurrent( cursor.get() , &md ) ) &&
+ !cursor->getsetdup( cursor->currLoc() ) ) {
n++;
+ BSONObj holder;
BSONElementSet temp;
- loadedObject = ! cc->getFieldsDotted( key , temp );
+ loadedObject = ! cc->getFieldsDotted( key , temp, holder );
for ( BSONElementSet::iterator i=temp.begin(); i!=temp.end(); ++i ) {
BSONElement e = *i;
@@ -118,13 +122,15 @@ namespace mongo {
}
}
- if ( loadedObject || md.loadedObject )
+ if ( loadedObject || md._loadedObject )
nscannedObjects++;
cursor->advance();
- if (!cc->yieldSometimes())
+ if (!cc->yieldSometimes( ClientCursor::MaybeCovered )) {
+ cc.release();
break;
+ }
RARELY killCurrentOp.checkForInterrupt();
}
@@ -139,6 +145,7 @@ namespace mongo {
b.appendNumber( "nscanned" , nscanned );
b.appendNumber( "nscannedObjects" , nscannedObjects );
b.appendNumber( "timems" , t.millis() );
+ b.append( "cursor" , cursorName );
result.append( "stats" , b.obj() );
}