summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2009-01-06 10:48:17 -0500
committerDwight <dmerriman@gmail.com>2009-01-06 10:48:17 -0500
commitbed528742b81f92442eb25a42fa51518432061b5 (patch)
tree62ab76db8f7658acbe01cc70f20936af1934c5b3 /db
parentb7b8bed9f7596791481ef7cf58c82dd61b081c16 (diff)
parent5cfe811560549d061f41770de3f00860aff8e406 (diff)
downloadmongo-bed528742b81f92442eb25a42fa51518432061b5.tar.gz
Merge branch 'master' of ssh://git.10gen.com/data/gitroot/p
Diffstat (limited to 'db')
-rw-r--r--db/dbwebserver.cpp43
-rw-r--r--db/jsobj.cpp5
-rw-r--r--db/jsobj.h4
3 files changed, 40 insertions, 12 deletions
diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp
index 81365df26b3..aecb955c913 100644
--- a/db/dbwebserver.cpp
+++ b/db/dbwebserver.cpp
@@ -271,18 +271,39 @@ public:
void handleRESTQuery( string ns , string action , map<string,string> & params , int & responseCode , stringstream & out ){
static DBDirectClient db;
- int skip = _getOption( params["skip"] , 0 );
- int num = _getOption( params["count" ] , 0 );
+ Timer t;
- int one = 0;
+ int skip = _getOption( params["skip"] , 0 );
+ int num = _getOption( params["limit"] , _getOption( params["count" ] , 1000 ) ); // count is old, limit is new
+ int one = 0;
if ( params["one"].size() > 0 && tolower( params["one"][0] ) == 't' ){
num = 1;
one = 1;
}
- BSONObjBuilder query;
- auto_ptr<DBClientCursor> cursor = db.query( ns.c_str() , query.doneAndDecouple() , num , skip );
+ BSONObjBuilder queryBuilder;
+
+ for ( map<string,string>::iterator i = params.begin(); i != params.end(); i++ ){
+ if ( ! i->first.find( "filter_" ) == 0 )
+ continue;
+
+ const char * field = i->first.substr( 7 ).c_str();
+ const char * val = i->second.c_str();
+
+ char * temp;
+
+ // TODO: this is how i guess if something is a number. pretty lame right now
+ float number = strtof( val , &temp );
+ if ( temp != val )
+ queryBuilder.append( field , number );
+ else
+ queryBuilder.append( field , val );
+ }
+
+ BSONObj query = queryBuilder.doneAndDecouple();
+
+ auto_ptr<DBClientCursor> cursor = db.query( ns.c_str() , query, num , skip );
if ( one ){
if ( cursor->more() ){
@@ -296,20 +317,22 @@ public:
}
out << "{\n";
- //ss << " \"total_rows\" : 0 ,\n";
out << " \"offset\" : " << skip << ",\n";
out << " \"rows\": [\n";
- int first = 1;
+ int howMany = 0;
while ( cursor->more() ){
- if ( first )
- first = 0;
- else
+ if ( howMany++ )
out << " ,\n";
BSONObj obj = cursor->next();
out << " " << obj.jsonString();
+
}
out << "\n ]\n\n";
+
+ out << " \"total_rows\" : " << howMany << " ,\n";
+ out << " \"query\" : " << query.jsonString() << " ,\n";
+ out << " \"millis\" : " << t.millis() << " ,\n";
out << "}\n";
}
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index 5cd5060be76..4d2749eb800 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -165,8 +165,9 @@ string BSONElement::jsonString( JsonStringFormat format, bool includeFieldNames
break;
case NumberInt:
case NumberDouble:
- if ( number() >= numeric_limits< double >::min() &&
- number() <= numeric_limits< double >::max() ) {
+ if ( number() == 0 ||
+ ( number() >= numeric_limits< double >::min() &&
+ number() <= numeric_limits< double >::max() ) ){
s.precision( 50 );
s << number();
} else {
diff --git a/db/jsobj.h b/db/jsobj.h
index 8821bbbbc67..8df8141fe40 100644
--- a/db/jsobj.h
+++ b/db/jsobj.h
@@ -351,6 +351,10 @@ public:
};
BSONElement getField(const char *name) const; /* return has eoo() true if no match */
+ bool hasField( const char * name )const {
+ return ! getField( name ).eoo();
+ }
+
// returns "" if DNE or wrong type
const char * getStringField(const char *name);