summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-06-28 13:46:59 -0400
committerDwight <dmerriman@gmail.com>2008-06-28 13:46:59 -0400
commitd85e75b674f5ea45e936ca3a5409b54d937f361a (patch)
treefdfbc6b9b39e91d147a1d019ce980717fd0e0a5f
parentb1a480423bb8136f69a573413dcc097a900342a4 (diff)
downloadmongo-d85e75b674f5ea45e936ca3a5409b54d937f361a.tar.gz
switching locations
-rw-r--r--db/pdfile.cpp1
-rw-r--r--db/query.cpp18
2 files changed, 15 insertions, 4 deletions
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: <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<Cursor> c = getIndexCursor(ns, id_obj, empty_obj);
+ JSObj query = cmd.getObjectField("query");
+
+ auto_ptr<Cursor> 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++;