Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix $ update with indexes in some cases SERVER-1339

  • Loading branch information...
commit c2aa43941528b581d61e1b8ab8217ed3e657fed0 1 parent 51ad1d3
@erh erh authored
Showing with 27 additions and 3 deletions.
  1. +4 −3 db/update.cpp
  2. +8 −0 db/update.h
  3. +15 −0 jstests/update_arraymatch5.js
View
7 db/update.cpp
@@ -24,7 +24,7 @@
#include "repl.h"
#include "update.h"
-//#define DEBUGUPDATE(x) cout << x << endl;
+#define DEBUGUPDATE(x) cout << x << endl;
#define DEBUGUPDATE(x)
namespace mongo {
@@ -889,10 +889,11 @@ namespace mongo {
if ( modsIsIndexed <= 0 && mss->canApplyInPlace() ){
mss->applyModsInPlace();// const_cast<BSONObj&>(onDisk) );
-
+
+ DEBUGUPDATE( "\t\t\t doing in place update" );
if ( profile )
ss << " fastmod ";
-
+
if ( modsIsIndexed ){
seenObjects.insert( loc );
}
View
8 db/update.h
@@ -129,6 +129,14 @@ namespace mongo {
StringBuilder buf( fullName.size() + 1 );
for ( size_t i=0; i<fullName.size(); i++ ){
char c = fullName[i];
+
+ if ( c == '$' &&
+ i > 0 && fullName[i-1] == '.' &&
+ fullName[i+1] == '.' ){
+ i++;
+ continue;
+ }
+
buf << c;
if ( c != '.' )
View
15 jstests/update_arraymatch5.js
@@ -0,0 +1,15 @@
+
+t = db.update_arraymatch5
+t.drop();
+
+t.insert({abc:{visible:true}, testarray:[{foobar_id:316, visible:true, xxx: 1}]});
+t.ensureIndex({'abc.visible':1, 'testarray.visible':1 , 'testarray.xxx': 1});
+assert( t.findOne({'abc.visible':true, testarray:{'$elemMatch': {visible:true, xxx:1}}}) , "A1" )
+assert( t.findOne({testarray:{'$elemMatch': {visible:true, xxx:1}}}) , "A2" );
+
+t.update({'testarray.foobar_id':316}, {'$set': {'testarray.$.visible': true, 'testarray.$.xxx': 2}}, false, true);
+
+assert( t.findOne() , "B1" );
+assert( t.findOne({testarray:{'$elemMatch': {visible:true, xxx:2}}}) , "B2" )
+assert( t.findOne({'abc.visible':true, testarray:{'$elemMatch': {visible:true, xxx:2}}}) , "B3" );
+assert.eq( 1 , t.find().count() , "B4" );
Please sign in to comment.
Something went wrong with that request. Please try again.