diff --git a/db/query.cpp b/db/query.cpp index c040bfdde61..c6b6cc5086f 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -288,22 +288,25 @@ namespace mongo { void getMods( const BSONObj &from ); bool applyModsInPlace( const BSONObj &obj ) const; BSONObj createNewFromMods( const BSONObj &obj ); + void checkUnindexed( const set& idxKeys ) const { for ( vector::const_iterator i = mods_.begin(); i != mods_.end(); i++ ) { // check if there is an index key that is a parent of mod for( const char *dot = strchr( i->fieldName, '.' ); dot; dot = strchr( dot + 1, '.' ) ) if ( idxKeys.count( string( i->fieldName, dot - i->fieldName ) ) ) - uassert("can't $inc/$set an indexed field", false); + uassert("E12010 can't $inc/$set an indexed field ", false); string fullName = i->fieldName; // check if there is an index key equal to mod if ( idxKeys.count(fullName) ) - uassert("can't $inc/$set an indexed field", false); + uassert("E12011 can't $inc/$set an indexed field", false); // check if there is an index key that is a child of mod set< string >::const_iterator j = idxKeys.upper_bound( fullName ); - if ( j != idxKeys.end() && j->find( fullName ) == 0 ) - uassert("can't $inc/$set an indexed field", false); + if ( j != idxKeys.end() && j->find( fullName ) == 0 && (*j)[fullName.size()] == '.' ){ + uassert("E12012 can't $inc/$set an indexed field", false); + } } } + unsigned size() const { return mods_.size(); } bool haveModForField( const char *fieldName ) const { // Presumably the number of mods is small, so this loop isn't too expensive. diff --git a/jstests/update5.js b/jstests/update5.js index 4ff9f1b9d38..d3e443565f7 100644 --- a/jstests/update5.js +++ b/jstests/update5.js @@ -7,6 +7,7 @@ function go( key ){ function check( num , name ){ assert.eq( 1 , t.find().count() , tojson( key ) + " count " + name ); + printjson( t.findOne() ); assert.eq( num , t.findOne().n , tojson( key ) + " value " + name ); } @@ -36,5 +37,6 @@ go( { a : 5 , b : 7 } ); go( { a : null , b : 7 } ); go( { referer: 'blah' } ); -//go( { referer: 'blah', name: 'bar' } ); -//go( { date: null, referer: 'blah', name: 'bar' } ); +go( { referer: 'blah', lame: 'bar' } ); +go( { referer: 'blah', name: 'bar' } ); +go( { date: null, referer: 'blah', name: 'bar' } );