Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

return arrays if arrays given SERVER-3661

  • Loading branch information...
commit a695bea89c338f6f458abc258eee16f415edeae1 1 parent 771f7f7
gregs authored erh committed
Showing with 24 additions and 1 deletion.
  1. +5 −0 bson/bsonobj.h
  2. +4 −1 db/geo/2d.cpp
  3. +15 −0 db/jsobj.cpp
View
5 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;
View
5 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();
}
View
15 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 );
Please sign in to comment.
Something went wrong with that request. Please try again.