summaryrefslogtreecommitdiff
path: root/db/jsobj.cpp
diff options
context:
space:
mode:
authorKristina <kristina@10gen.com>2011-05-13 15:27:25 -0400
committerKristina <kristina@10gen.com>2011-05-13 15:27:25 -0400
commit08b057a79dd8021fb675576423b5081238a309b8 (patch)
treefab662e99ef5ea8697f566242d8f38ac554078ce /db/jsobj.cpp
parent4e1187f46b22e5b6c16d1179dc0bcbbcd3efda4a (diff)
downloadmongo-08b057a79dd8021fb675576423b5081238a309b8.tar.gz
json support for undefined
Diffstat (limited to 'db/jsobj.cpp')
-rw-r--r--db/jsobj.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index 273a8233256..c392a21d603 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -98,7 +98,7 @@ namespace mongo {
string BSONElement::jsonString( JsonStringFormat format, bool includeFieldNames, int pretty ) const {
BSONType t = type();
if ( t == Undefined )
- return "";
+ return "undefined";
stringstream s;
if ( includeFieldNames )
@@ -142,19 +142,28 @@ namespace mongo {
s << "[ ";
BSONObjIterator i( embeddedObject() );
BSONElement e = i.next();
- if ( !e.eoo() )
+ if ( !e.eoo() ) {
+ int count = 0;
while ( 1 ) {
if( pretty ) {
s << '\n';
for( int x = 0; x < pretty; x++ )
s << " ";
}
- s << e.jsonString( format, false, pretty?pretty+1:0 );
- e = i.next();
+
+ if (strtol(e.fieldName(), 0, 10) > count) {
+ s << "undefined";
+ }
+ else {
+ s << e.jsonString( format, false, pretty?pretty+1:0 );
+ e = i.next();
+ }
+ count++;
if ( e.eoo() )
break;
s << ", ";
}
+ }
s << " ]";
break;
}