diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-02-16 16:23:25 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-02-16 16:24:23 -0500 |
commit | d1e3572f45318511402b8482e7c63d3446d52ec8 (patch) | |
tree | 4b79ec8a281a3ea63a943b1ecc7dffa649b132c8 | |
parent | 2b7dd6ad055fa1b8ec9f63dae394985f58a8c417 (diff) | |
download | mongo-d1e3572f45318511402b8482e7c63d3446d52ec8.tar.gz |
re-hydrate index values
-rw-r--r-- | db/jsobj.cpp | 11 | ||||
-rw-r--r-- | db/jsobj.h | 1 | ||||
-rw-r--r-- | db/query.cpp | 10 | ||||
-rw-r--r-- | jstests/index_diag.js | 4 |
4 files changed, 21 insertions, 5 deletions
diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 2b3359ceb6b..ec08c25b453 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -1612,6 +1612,17 @@ namespace mongo { } + void BSONObjBuilder::appendKeys( const BSONObj& keyPattern , const BSONObj& values ){ + BSONObjIterator i(keyPattern); + BSONObjIterator j(values); + + while ( i.more() && j.more() ){ + appendAs( j.next() , i.next().fieldName() ); + } + + assert( ! i.more() ); + assert( ! j.more() ); + } int BSONElementFieldSorter( const void * a , const void * b ){ const char * x = *((const char**)a); diff --git a/db/jsobj.h b/db/jsobj.h index 37bbcf42fd1..6f3f0cb4422 100644 --- a/db/jsobj.h +++ b/db/jsobj.h @@ -1507,6 +1507,7 @@ namespace mongo { b.decouple(); // post done() call version. be sure jsobj frees... } + void appendKeys( const BSONObj& keyPattern , const BSONObj& values ); private: static const string numStrs[100]; // cache of 0 to 99 inclusive diff --git a/db/query.cpp b/db/query.cpp index 5cfc36223a7..b60939b056d 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -635,10 +635,14 @@ namespace mongo { } } else { - if ( _pq.returnKey() ) - _buf.append( js.objdata() , js.objsize() ); - else + if ( _pq.returnKey() ){ + BSONObjBuilder bb( _buf ); + bb.appendKeys( _c->indexKeyPattern() , js ); + bb.done(); + } + else { fillQueryResultFromObj( _buf , _pq.getFields() , js ); + } _n++; if ( _pq.enoughForFirstBatch( _n , _buf.len() ) ){ /* if only 1 requested, no cursor saved for efficiency...we assume it is findOne() */ diff --git a/jstests/index_diag.js b/jstests/index_diag.js index 3c6cb6c0f22..38169b3839d 100644 --- a/jstests/index_diag.js +++ b/jstests/index_diag.js @@ -19,8 +19,8 @@ for ( i=1; i<4; i++ ){ o = { _id : i , x : -i } t.insert( o ); all.push( o ); - ids.push( { "" : i } ); - xs.push( { "" : -i } ); + ids.push( { _id : i } ); + xs.push( { x : -i } ); } assert.eq( all , t.find().sort( { _id : 1 } ).toArray() , "A1" ); |