diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 28cd97f786c..4c9ea6e3985 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -665,6 +665,7 @@ void _unindexRecord(const char *ns, IndexDetails& id, JSObj& obj, const DiskLoc& } } +/* unindex all keys in all indexes for this record. */ void unindexRecord(const char *ns, NamespaceDetails *d, Record *todelete, const DiskLoc& dl) { if( d->nIndexes == 0 ) return; JSObj obj(todelete); diff --git a/db/query.cpp b/db/query.cpp index 144c8d27f1a..7c90d232e9e 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -30,7 +30,7 @@ JSObj emptyObj((char *) &emptyObject); int getGtLtOp(Element& e); void appendElementHandlingGtLt(JSObjBuilder& b, Element& e); -int runCount(const char *ns, const JSObj& cmd, string& err); +int runCount(const char *ns, JSObj& cmd, string& err); /* todo: _ cache query plans _ use index on partial match with the query @@ -711,19 +711,29 @@ JSObj empty_obj = fromjson("{}"); /* { count: "collectionname"[, query: ] } returns -1 on error. */ -int runCount(const char *ns, const JSObj& cmd, string& err) { +int runCount(const char *ns, JSObj& cmd, string& err) { NamespaceDetails *d = nsdetails(ns); if( d == 0 ) { err = "ns does not exist"; return -1; } - auto_ptr c = getIndexCursor(ns, id_obj, empty_obj); + JSObj query = cmd.getObjectField("query"); + + auto_ptr c; + if( query.isEmpty() ) { + c = getIndexCursor(ns, id_obj, empty_obj); + } else { + c = getIndexCursor(ns, query, empty_obj); + } + if( c.get() == 0 ) { cout << "TEMP: table scan" << endl; c = findTableScan(ns, empty_obj); } - else cout << "TEMP: indexed scan" << endl; + else + cout << "TEMP: indexed scan" << endl; + int count = 0; if( c->ok() ) { count++;