diff options
author | Dwight <dmerriman@gmail.com> | 2008-07-22 18:12:32 -0400 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2008-07-22 18:12:32 -0400 |
commit | 38dbc34d454f692c1583a797790ef639cbc12a8c (patch) | |
tree | 6145d0e185bdeade516b0e8620411f2cb8890d02 | |
parent | 27cbdfdc8c320bcf5cb08f5277fc1d77167cc134 (diff) | |
download | mongo-38dbc34d454f692c1583a797790ef639cbc12a8c.tar.gz |
a little defensive plus better json output
-rw-r--r-- | db/jsobj.cpp | 14 | ||||
-rw-r--r-- | db/jsobj.h | 30 | ||||
-rw-r--r-- | db/query.cpp | 11 |
3 files changed, 39 insertions, 16 deletions
diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 5d7c16f6be8..423adb07131 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -153,10 +153,18 @@ string Element::toString() { s << '"' << valuestr() << '"'; } break; + case DBRef: + s << fieldName(); + s << " : DBRef('" << valuestr() << "',"; + { + OID *x = (OID *) (valuestr() + valuestrsize()); + s << hex << x->a << x->b << dec << ')'; + } + break; case jstOID: - s << fieldName() << " : ObjId("; - s << hex << oid().a << hex << oid().b << ')'; - break; + s << fieldName() << " : ObjId("; + s << hex << oid().a << oid().b << dec << ')'; + break; default: s << fieldName() << ": ?type=" << type(); break; diff --git a/db/jsobj.h b/db/jsobj.h index 2bb773d2710..5415c75f861 100644 --- a/db/jsobj.h +++ b/db/jsobj.h @@ -61,20 +61,19 @@ struct OID { totalSize includes itself. Data: - Bool: <byte> - EOO: nothing follows + Bool: <byte> + EOO: nothing follows Undefined: nothing follows - OID: an OID object - Number: <double> - String: <unsigned32 strsizewithnull><cstring> - Date: <8bytes> - Regex: <cstring regex><cstring options> - Object: a nested object, leading with its entire size, which terminates with EOO. - Array: same as object - BinData: - <int len> - <byte subtype> - <byte[len] data> + OID: an OID object + Number: <double> + String: <unsigned32 strsizewithnull><cstring> + Date: <8bytes> + Regex: <cstring regex><cstring options> + Object: a nested object, leading with its entire size, which terminates with EOO. + Array: same as object + DBRef: <strlen> <cstring ns> <oid> + DBRef is a database reference: basically a collection name plus an Object ID + BinData: <int len> <byte subtype> <byte[len] data> */ /* db operation message format @@ -413,6 +412,11 @@ private: BufBuilder b; }; +/* iterator for a JSObj + + Note each JSObj ends with an EOO element: so you will get more() on an empty + object, although next().eoo() will be true. +*/ class JSElemIter { public: JSElemIter(const JSObj& jso) { diff --git a/db/query.cpp b/db/query.cpp index 3fa4d66f092..f78c70ad735 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -891,6 +891,17 @@ QueryResult* runQuery(Message& message, const char *ns, int ntoskip, int _ntoret if( query.isEmpty() && order.isEmpty() ) query = jsobj; + /* The ElemIter will not be happy if this isn't really an object. So throw exception + here when that is true. + (Which may indicate bad data from appserver?) + */ + if( query.objsize() == 0 ) { + cout << "Bad query object?\n jsobj:"; + cout << jsobj.toString() << "\n query:"; + cout << query.toString() << endl; + assert(false); + } + auto_ptr<JSMatcher> matcher(new JSMatcher(query)); JSMatcher &debug1 = *matcher; assert( debug1.getN() < 5000 ); |