mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
use extractFields which is now correct to fix SERVER-257
This commit is contained in:
parent
89d5e0fe45
commit
af13f83c61
@ -1161,19 +1161,7 @@ namespace mongo {
|
||||
}
|
||||
|
||||
BSONObj getKey( const BSONObj& obj , const BSONObj& keyPattern , const string keyFunction , double avgSize ){
|
||||
BSONObjBuilder b( (int)(avgSize * 1.1) );
|
||||
|
||||
BSONObjIterator i( keyPattern );
|
||||
while ( i.more() ){
|
||||
const char * n = i.next().fieldName();
|
||||
BSONElement e = obj[n];
|
||||
if ( e.eoo() )
|
||||
b.appendNull( n );
|
||||
else
|
||||
b.append( e );
|
||||
}
|
||||
|
||||
return b.obj();
|
||||
return obj.extractFields( keyPattern );
|
||||
}
|
||||
|
||||
bool group( string realdbname , auto_ptr<DBClientCursor> cursor , BSONObj keyPattern , string keyFunction , string reduceCode , BSONObj initial , string& errmsg , BSONObjBuilder& result ){
|
||||
|
@ -38,3 +38,23 @@ c = {key: {a:1}, cond: {}, initial: {"count": 0}, reduce: function(obj, prev) {
|
||||
assert.eq( t.group( c ) , t.groupcmd( c ) , "ZZZZ" );
|
||||
|
||||
|
||||
t.drop();
|
||||
|
||||
t.save( { name : { first : "a" , last : "A" } } );
|
||||
t.save( { name : { first : "b" , last : "B" } } );
|
||||
t.save( { name : { first : "a" , last : "A" } } );
|
||||
|
||||
|
||||
p = { key : { 'name.first' : true } ,
|
||||
reduce : function(obj,prev) { prev.count++; },
|
||||
initial: { count: 0 }
|
||||
};
|
||||
|
||||
res = t.group( p );
|
||||
assert.eq( 2 , res.length , "Z1" );
|
||||
assert.eq( "a" , res[0].first , "Z2" )
|
||||
assert.eq( "b" , res[1].first , "Z3" )
|
||||
assert.eq( 2 , res[0].count , "Z4" )
|
||||
assert.eq( 1 , res[1].count , "Z5" )
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user