From c1007834f6c7d724e824a91c60ab1e2aef2e07c9 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Wed, 5 May 2010 22:52:51 -0400 Subject: fix updates on indexes fields when using array offsets SERVER-1093 --- db/update.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- jstests/index_arr2.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 jstests/index_arr2.js diff --git a/db/update.h b/db/update.h index 5d20114fe97..3c4daabaeae 100644 --- a/db/update.h +++ b/db/update.h @@ -100,12 +100,13 @@ namespace mongo { } } - bool isIndexed( const set& idxKeys ) const { + static bool isIndexed( const string& fullName , const set& idxKeys ){ + const char * fieldName = fullName.c_str(); // check if there is an index key that is a parent of mod for( const char *dot = strchr( fieldName, '.' ); dot; dot = strchr( dot + 1, '.' ) ) if ( idxKeys.count( string( fieldName, dot - fieldName ) ) ) return true; - string fullName = fieldName; + // check if there is an index key equal to mod if ( idxKeys.count(fullName) ) return true; @@ -113,6 +114,49 @@ namespace mongo { set< string >::const_iterator j = idxKeys.upper_bound( fullName ); if ( j != idxKeys.end() && j->find( fullName ) == 0 && (*j)[fullName.size()] == '.' ) return true; + + return false; + } + + bool isIndexed( const set& idxKeys ) const { + string fullName = fieldName; + + if ( isIndexed( fullName , idxKeys ) ) + return true; + + if ( strstr( fieldName , "." ) ){ + // check for a.0.1 + StringBuilder buf( fullName.size() + 1 ); + for ( size_t i=0; i