--- mongodb-src-r1.6.5/db/update.h 2010-12-08 12:33:20.000000000 -0200 +++ mongodb-src-r1.6.5-patched/db/update.h 2011-02-05 14:22:42.000000000 -0200 @@ -33,7 +33,7 @@ struct Mod { // See opFromStr below // 0 1 2 3 4 5 6 7 8 9 10 11 - enum Op { INC, SET, PUSH, PUSH_ALL, PULL, PULL_ALL , POP, UNSET, BITAND, BITOR , BIT , ADDTOSET } op; + enum Op { INC, SET, PUSH, PUSH_ALL, PULL, PULL_ALL , POP, UNSET, BITAND, BITOR , BIT , ADDTOSET, MULTIPLY } op; static const char* modNames[]; static unsigned modNamesNum; @@ -84,6 +84,9 @@ template< class Builder > void appendIncremented( Builder& bb , const BSONElement& in, ModState& ms ) const; + + template< class Builder > + void appendMultiplied( Builder& bb , const BSONElement& in, ModState& ms ) const; bool operator<( const Mod &other ) const { return strcmp( fieldName, other.fieldName ) < 0; @@ -304,6 +307,10 @@ } } + case 'm': { + if ( fn[2] == 'u' && fn[3] == 'l' && fn[4] == 't' && fn[5] == 'i' && fn[6] == 'p' && fn[7] == 'l' && fn[8] == 'y') + return Mod::MULTIPLY; + } default: break; } uassert( 10161 , "Invalid modifier specified " + string( fn ), false ); --- mongodb-src-r1.6.5/db/update.cpp 2010-12-08 12:33:20.000000000 -0200 +++ mongodb-src-r1.6.5-patched/db/update.cpp 2011-02-05 14:15:32.000000000 -0200 @@ -72,6 +72,27 @@ } template< class Builder > + void Mod::appendMultiplied( Builder& bb , const BSONElement& in, ModState& ms ) const { + BSONType a = in.type(); + BSONType b = elt.type(); + + if ( a == NumberDouble || b == NumberDouble ){ + ms.incType = NumberDouble; + ms.incdouble = elt.numberDouble() * in.numberDouble(); + } + else if ( a == NumberLong || b == NumberLong ){ + ms.incType = NumberLong; + ms.inclong = elt.numberLong() * in.numberLong(); + } + else { + ms.incType = NumberInt; + ms.incint = elt.numberInt() * in.numberInt(); + } + + ms.appendIncValue( bb , false ); + } + + template< class Builder > void appendUnset( Builder &b ) { } @@ -299,6 +320,11 @@ break; } + case MULTIPLY: { + appendMultiplied( b , in , ms ); + break; + } + default: stringstream ss; ss << "Mod::apply can't handle type: " << op;