0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

Merge branch 'master' of git@github.com:mongodb/mongo

This commit is contained in:
Dwight 2009-10-02 16:58:15 -04:00
commit ff458d03b7
3 changed files with 22 additions and 16 deletions

View File

@ -48,9 +48,9 @@ namespace mongo {
for ( list<BSONObj>::iterator i=values.begin(); i!=values.end(); i++){ for ( list<BSONObj>::iterator i=values.begin(); i!=values.end(); i++){
BSONObj o = *i; BSONObj o = *i;
if ( n == 0 ){ if ( n == 0 ){
reduceArgs.append( o["key"] ); reduceArgs.append( o["_id"] );
BSONObjBuilder temp; BSONObjBuilder temp;
temp.append( o["key"] ); temp.append( o["_id"] );
key = temp.obj(); key = temp.obj();
} }
valueBuilder.appendAs( o["value"] , BSONObjBuilder::numStr( n++ ).c_str() ); valueBuilder.appendAs( o["value"] , BSONObjBuilder::numStr( n++ ).c_str() );
@ -65,7 +65,7 @@ namespace mongo {
return BSONObj(); return BSONObj();
} }
BSONObjBuilder b; BSONObjBuilder b;
b.append( key["key"] ); b.append( key["_id"] );
s->append( b , "value" , "return" ); s->append( b , "value" , "return" );
return b.obj(); return b.obj();
} }
@ -180,7 +180,7 @@ namespace mongo {
{ {
assert( i.more() ); assert( i.more() );
BSONObjBuilder b; BSONObjBuilder b;
b.appendAs( i.next() , "key" ); b.appendAs( i.next() , "_id" );
key = b.obj(); key = b.obj();
} }
@ -224,7 +224,7 @@ namespace mongo {
if ( values.size() == 0 ) if ( values.size() == 0 )
return; return;
BSONObj key = values.begin()->extractFields( BSON( "key" << 1 ) ); BSONObj key = values.begin()->extractFields( BSON( "_id" << 1 ) );
if ( values.size() == 1 ){ if ( values.size() == 1 ){
assert( db.count( resultColl , key ) == 1 ); assert( db.count( resultColl , key ) == 1 );
@ -259,7 +259,6 @@ namespace mongo {
string finalOutputShort = finalOutput.substr( database->name.size() + 1 ); string finalOutputShort = finalOutput.substr( database->name.size() + 1 );
log(1) << "\t resultColl: " << resultColl << " short: " << resultCollShort << endl; log(1) << "\t resultColl: " << resultColl << " short: " << resultCollShort << endl;
db.dropCollection( resultColl ); db.dropCollection( resultColl );
db.ensureIndex( resultColl , BSON( "key" << 1 ) );
int num = 0; int num = 0;
@ -305,9 +304,9 @@ namespace mongo {
BSONObj prev; BSONObj prev;
list<BSONObj> all; list<BSONObj> all;
BSONObj sortKey = BSON( "key" << 1 ); BSONObj sortKey = BSON( "_id" << 1 );
cursor = db.query( resultColl, Query().sort( BSON( "key" << 1 ) ) ); cursor = db.query( resultColl, Query().sort( sortKey ) );
while ( cursor->more() ){ while ( cursor->more() ){
BSONObj o = cursor->next().getOwned(); BSONObj o = cursor->next().getOwned();

7
jstests/basicb.js Normal file
View File

@ -0,0 +1,7 @@
t = db.basicb;
t.drop();
assert.throws( "t.insert( { '$a' : 5 } );" );
t.insert( { '$a' : 5 } , true );

View File

@ -32,7 +32,7 @@ x = db[res.result];
assert.eq( 3 , x.find().count() , "B" ); assert.eq( 3 , x.find().count() , "B" );
x.find().forEach( printjson ); x.find().forEach( printjson );
z = {}; z = {};
x.find().forEach( function(a){ z[a.key] = a.value.count; } ); x.find().forEach( function(a){ z[a._id] = a.value.count; } );
printjson( z ); printjson( z );
assert.eq( 3 , z.keySet().length , "C" ); assert.eq( 3 , z.keySet().length , "C" );
assert.eq( 2 , z.a , "D" ); assert.eq( 2 , z.a , "D" );
@ -44,7 +44,7 @@ res = db.runCommand( { mapreduce : "mr1" , map : m , reduce : r , query : { x :
assert.eq( 2 , res.numObjects , "B" ); assert.eq( 2 , res.numObjects , "B" );
x = db[res.result]; x = db[res.result];
z = {}; z = {};
x.find().forEach( function(a){ z[a.key] = a.value.count; } ); x.find().forEach( function(a){ z[a._id] = a.value.count; } );
assert.eq( 1 , z.a , "C1" ); assert.eq( 1 , z.a , "C1" );
assert.eq( 1 , z.b , "C2" ); assert.eq( 1 , z.b , "C2" );
assert.eq( 2 , z.c , "C3" ); assert.eq( 2 , z.c , "C3" );
@ -55,7 +55,7 @@ assert.eq( 2 , res.numObjects , "B2" );
assert.eq( "foo" , res.result , "B2-c" ); assert.eq( "foo" , res.result , "B2-c" );
x = db[res.result]; x = db[res.result];
z = {}; z = {};
x.find().forEach( function(a){ z[a.key] = a.value.count; } ); x.find().forEach( function(a){ z[a._id] = a.value.count; } );
assert.eq( 1 , z.a , "C1a" ); assert.eq( 1 , z.a , "C1a" );
assert.eq( 1 , z.b , "C2a" ); assert.eq( 1 , z.b , "C2a" );
assert.eq( 2 , z.c , "C3a" ); assert.eq( 2 , z.c , "C3a" );
@ -73,11 +73,11 @@ assert.eq( 999 , res.numObjects , "Z1" );
x = db[res.result]; x = db[res.result];
x.find().forEach( printjson ) x.find().forEach( printjson )
assert.eq( 4 , x.find().count() , "Z2" ); assert.eq( 4 , x.find().count() , "Z2" );
assert.eq( "a,b,c,d" , x.distinct( "key" ) , "Z3" ); assert.eq( "a,b,c,d" , x.distinct( "_id" ) , "Z3" );
assert.eq( 2 , x.findOne( { key : "a" } ).value.count , "ZA" ); assert.eq( 2 , x.findOne( { _id : "a" } ).value.count , "ZA" );
assert.eq( 998 , x.findOne( { key : "b" } ).value.count , "ZB" ); assert.eq( 998 , x.findOne( { _id : "b" } ).value.count , "ZB" );
assert.eq( 3 , x.findOne( { key : "c" } ).value.count , "ZC" ); assert.eq( 3 , x.findOne( { _id : "c" } ).value.count , "ZC" );
assert.eq( 995 , x.findOne( { key : "d" } ).value.count , "ZD" ); assert.eq( 995 , x.findOne( { _id : "d" } ).value.count , "ZD" );
print( Date.timeFunc( print( Date.timeFunc(
function(){ function(){