fix inc with compound indexes SERVER-178

This commit is contained in:
Eliot Horowitz
2009-07-24 14:33:11 -04:00
parent de9d456c35
commit 8fe350ff00
2 changed files with 11 additions and 6 deletions

View File

@@ -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<string>& idxKeys ) const {
for ( vector<Mod>::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.