diff options
author | gregs <greg@10gen.com> | 2011-09-29 12:22:30 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-11-16 13:07:32 -0500 |
commit | a695bea89c338f6f458abc258eee16f415edeae1 (patch) | |
tree | f3c582678777a40e117cc75b90019555c3ee68b1 | |
parent | 771f7f7dd6a6c5634b5990572f89bdd4b1849182 (diff) | |
download | mongo-a695bea89c338f6f458abc258eee16f415edeae1.tar.gz |
return arrays if arrays given SERVER-3661
-rw-r--r-- | bson/bsonobj.h | 5 | ||||
-rw-r--r-- | db/geo/2d.cpp | 5 | ||||
-rw-r--r-- | db/jsobj.cpp | 15 |
3 files changed, 24 insertions, 1 deletions
diff --git a/bson/bsonobj.h b/bson/bsonobj.h index df6c85b923d..486a3e6ecc3 100644 --- a/bson/bsonobj.h +++ b/bson/bsonobj.h @@ -254,6 +254,11 @@ namespace mongo { BSONElement getFieldUsingIndexNames(const char *fieldName, const BSONObj &indexKey) const; + /** arrays are bson objects with numeric and increasing field names + @return true if field names are numeric and increasing + */ + bool couldBeArray() const; + /** @return the raw data of the object */ const char *objdata() const { return _objdata; diff --git a/db/geo/2d.cpp b/db/geo/2d.cpp index b873490e3ee..40df5e2ffea 100644 --- a/db/geo/2d.cpp +++ b/db/geo/2d.cpp @@ -2647,7 +2647,10 @@ namespace mongo { BSONObjBuilder bb( arr.subobjStart( BSONObjBuilder::numStr( x++ ) ) ); bb.append( "dis" , dis ); - if( includeLocs ) bb.append( "loc" , p._pt ); + if( includeLocs ){ + if( p._pt.couldBeArray() ) bb.append( "loc", BSONArray( p._pt ) ); + else bb.append( "loc" , p._pt ); + } bb.append( "obj" , p._o ); bb.done(); } diff --git a/db/jsobj.cpp b/db/jsobj.cpp index dcb77447873..9644a87aa3a 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -753,6 +753,21 @@ namespace mongo { return n; } + bool BSONObj::couldBeArray() const { + BSONObjIterator i( *this ); + int index = 0; + while( i.moreWithEOO() ){ + BSONElement e = i.next(); + if( e.eoo() ) break; + + // TODO: If actually important, may be able to do int->char* much faster + if( strcmp( e.fieldName(), ((string)( str::stream() << index )).c_str() ) != 0 ) + return false; + index++; + } + return true; + } + BSONObj BSONObj::clientReadable() const { BSONObjBuilder b; BSONObjIterator i( *this ); |