Permalink
Browse files

SERVER-5885 During an update, only advance past multiple iterates of …

…the same document when deduping is enabled.
  • Loading branch information...
1 parent 48b8dc9 commit e15ed2dc0651e35cba5e6c4b4ca76d3d0037e3ec @astaple astaple committed May 25, 2012
Showing with 33 additions and 8 deletions.
  1. +17 −0 jstests/geo_update3.js
  2. +16 −8 src/mongo/db/ops/update.cpp
View
@@ -0,0 +1,17 @@
+// Updates are applied once per location to a document with multiple locations iterated
+// consecutively. This is a descriptive, not a normative test. SERVER-5885
+
+t = db.jstests_geo_update3;
+t.drop();
+
+t.ensureIndex( { loc:'2d' } );
+// Save a document with two locations.
+t.save( { loc:[ [ 0, 0 ], [ 1, 1 ] ] } );
+
+// The update matches both locations without deduping them.
+t.update( { loc:{ $within:{ $center:[ [ 0, 0 ], 2 ], $uniqueDocs:false } } },
+ { $inc:{ touchCount:1 } }, false, true );
+
+// The document is updated twice.
+assert.eq( 2, db.getLastErrorObj().n );
+assert.eq( 2, t.findOne().touchCount );
@@ -320,14 +320,22 @@ namespace mongo {
if ( isOperatorUpdate ) {
if ( multi ) {
- c->advance(); // go to next record in case this one moves
- if ( autoDedup && seenObjects.count( loc ) ) {
- continue;
- }
- // SERVER-5198 Advance past the document to be modified, but see
- // SERVER-5725.
- while( c->ok() && loc == c->currLoc() ) {
- c->advance();
+ // go to next record in case this one moves
+ c->advance();
+
+ // Update operations are deduped for cursors that implement their own
+ // deduplication. In particular, some geo cursors are excluded.
+ if ( autoDedup ) {
+
+ if ( seenObjects.count( loc ) ) {
+ continue;
+ }
+
+ // SERVER-5198 Advance past the document to be modified, provided
+ // deduplication is enabled, but see SERVER-5725.
+ while( c->ok() && loc == c->currLoc() ) {
+ c->advance();
+ }
}
}

0 comments on commit e15ed2d

Please sign in to comment.