mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 17:10:48 +01:00
finish + switch to simpler+cleaner new object from mod code
This commit is contained in:
parent
4119148e97
commit
341cd83dd1
@ -81,6 +81,40 @@ namespace mongo {
|
|||||||
bb.done();
|
bb.done();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case PULL:
|
||||||
|
case PULL_ALL: {
|
||||||
|
uassert( "$pull/$pullAll can only be applied to an array" , in.type() == Array );
|
||||||
|
BSONObjBuilder bb( b.subarrayStart( shortFieldName ) );
|
||||||
|
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
BSONObjIterator i( in.embeddedObject() );
|
||||||
|
while ( i.more() ){
|
||||||
|
BSONElement e = i.next();
|
||||||
|
bool allowed = true;
|
||||||
|
|
||||||
|
if ( op == PULL ){
|
||||||
|
allowed = e.woCompare( elt , false ) != 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
BSONObjIterator j( elt.embeddedObject() );
|
||||||
|
while( j.more() ) {
|
||||||
|
BSONElement arrJ = j.next();
|
||||||
|
if ( e.woCompare( arrJ, false ) == 0 ){
|
||||||
|
allowed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( allowed )
|
||||||
|
bb.appendAs( e , bb.numStr( n++ ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
bb.done();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case POP: {
|
case POP: {
|
||||||
uassert( "$pop can only be applied to an array" , in.type() == Array );
|
uassert( "$pop can only be applied to an array" , in.type() == Array );
|
||||||
@ -117,7 +151,7 @@ namespace mongo {
|
|||||||
bb.done();
|
bb.done();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << "Mod::apply can't handle type: " << op;
|
ss << "Mod::apply can't handle type: " << op;
|
||||||
@ -269,7 +303,6 @@ namespace mongo {
|
|||||||
ModHolder::iterator mend = _mods.lower_bound( root + "{" );
|
ModHolder::iterator mend = _mods.lower_bound( root + "{" );
|
||||||
|
|
||||||
set<string> onedownseen;
|
set<string> onedownseen;
|
||||||
list<Mod*> toadd; // TODO: remove. this is a hack to make new and old impls. identical. when testing is complete, we should remove
|
|
||||||
|
|
||||||
while ( e.type() && m != mend ){
|
while ( e.type() && m != mend ){
|
||||||
string field = root + e.fieldName();
|
string field = root + e.fieldName();
|
||||||
@ -290,7 +323,7 @@ namespace mongo {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case LEFT_BEFORE:
|
case LEFT_BEFORE:
|
||||||
toadd.push_back( &(m->second) );
|
_appendNewFromMods( root , m->second , b , onedownseen );
|
||||||
m++;
|
m++;
|
||||||
continue;
|
continue;
|
||||||
case SAME:
|
case SAME:
|
||||||
@ -315,10 +348,6 @@ namespace mongo {
|
|||||||
e = es.next();
|
e = es.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( list<Mod*>::iterator i=toadd.begin(); i!=toadd.end(); i++ )
|
|
||||||
_appendNewFromMods( root , **i , b , onedownseen );
|
|
||||||
|
|
||||||
|
|
||||||
for ( ; m != mend; m++ ){
|
for ( ; m != mend; m++ ){
|
||||||
_appendNewFromMods( root , m->second , b , onedownseen );
|
_appendNewFromMods( root , m->second , b , onedownseen );
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ namespace mongo {
|
|||||||
BSONObj createNewFromMods_r( const BSONObj &obj );
|
BSONObj createNewFromMods_r( const BSONObj &obj );
|
||||||
|
|
||||||
BSONObj createNewFromMods( const BSONObj &obj ){
|
BSONObj createNewFromMods( const BSONObj &obj ){
|
||||||
return createNewFromMods_l( obj );
|
return createNewFromMods_r( obj );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -550,17 +550,18 @@ namespace UpdateTests {
|
|||||||
|
|
||||||
|
|
||||||
void test( BSONObj morig , BSONObj in , BSONObj wanted ){
|
void test( BSONObj morig , BSONObj in , BSONObj wanted ){
|
||||||
|
if ( false ){
|
||||||
int its = 1000;
|
int its = 1000;
|
||||||
double o = _test( morig , in , wanted , false , its );
|
double o = _test( morig , in , wanted , false , its );
|
||||||
double n = _test( morig , in , wanted , true , its );
|
double n = _test( morig , in , wanted , true , its );
|
||||||
double r = o / n;
|
double r = o / n;
|
||||||
cout << " new is : " << r << " x faster" << endl;
|
cout << " new is : " << r << " x faster" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
BSONObj m = morig.copy();
|
BSONObj m = morig.copy();
|
||||||
ModSet set;
|
ModSet set;
|
||||||
set.getMods( m );
|
set.getMods( m );
|
||||||
|
|
||||||
BSONObj out = set.createNewFromMods( in );
|
BSONObj out = set.createNewFromMods( in );
|
||||||
ASSERT_EQUALS( wanted , out );
|
ASSERT_EQUALS( wanted , out );
|
||||||
}
|
}
|
||||||
@ -596,7 +597,7 @@ namespace UpdateTests {
|
|||||||
BSONObj m = BSON( "$inc" << BSON( "x" << 1 ) );
|
BSONObj m = BSON( "$inc" << BSON( "x" << 1 ) );
|
||||||
test( m , BSON( "x" << 5 ) , BSON( "x" << 6 ) );
|
test( m , BSON( "x" << 5 ) , BSON( "x" << 6 ) );
|
||||||
test( m , BSON( "a" << 5 ) , BSON( "a" << 5 << "x" << 1 ) );
|
test( m , BSON( "a" << 5 ) , BSON( "a" << 5 << "x" << 1 ) );
|
||||||
test( m , BSON( "z" << 5 ) , BSON( "z" << 5 << "x" << 1 ) );
|
test( m , BSON( "z" << 5 ) , BSON( "x" << 1 << "z" << 5 ) );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -620,7 +621,7 @@ namespace UpdateTests {
|
|||||||
test( BSON( "$set" << BSON( "x" << 17 ) ) , BSONObj() , BSON( "x" << 17 ) );
|
test( BSON( "$set" << BSON( "x" << 17 ) ) , BSONObj() , BSON( "x" << 17 ) );
|
||||||
test( BSON( "$set" << BSON( "x" << 17 ) ) , BSON( "x" << 5 ) , BSON( "x" << 17 ) );
|
test( BSON( "$set" << BSON( "x" << 17 ) ) , BSON( "x" << 5 ) , BSON( "x" << 17 ) );
|
||||||
|
|
||||||
test( BSON( "$set" << BSON( "x.a" << 17 ) ) , BSON( "z" << 5 ) , BSON( "z" << 5 << "x" << BSON( "a" << 17 ) ) );
|
test( BSON( "$set" << BSON( "x.a" << 17 ) ) , BSON( "z" << 5 ) , BSON( "x" << BSON( "a" << 17 )<< "z" << 5 ) );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user