Skip to content

Commit 5bf6685

Browse files
committed
fix repl $inc issue SERVER-1161
1 parent 637dbb7 commit 5bf6685

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

db/update.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace mongo {
6767
ms.incint = elt.numberInt() + in.numberInt();
6868
}
6969

70-
ms.appendIncValue( bb );
70+
ms.appendIncValue( bb , false );
7171
}
7272

7373
template< class Builder >

db/update.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ namespace mongo {
413413
void appendForOpLog( BSONObjBuilder& b ) const {
414414
if ( incType ){
415415
BSONObjBuilder bb( b.subobjStart( "$set" ) );
416-
appendIncValue( bb );
416+
appendIncValue( bb , true );
417417
bb.done();
418418
return;
419419
}
@@ -434,14 +434,16 @@ namespace mongo {
434434
}
435435

436436
template< class Builder >
437-
void appendIncValue( Builder& b ) const {
437+
void appendIncValue( Builder& b , bool useFullName ) const {
438+
const char * n = useFullName ? m->fieldName : m->shortFieldName;
439+
438440
switch ( incType ){
439441
case NumberDouble:
440-
b.append( m->shortFieldName , incdouble ); break;
442+
b.append( n , incdouble ); break;
441443
case NumberLong:
442-
b.append( m->shortFieldName , inclong ); break;
444+
b.append( n , inclong ); break;
443445
case NumberInt:
444-
b.append( m->shortFieldName , incint ); break;
446+
b.append( n , incint ); break;
445447
default:
446448
assert(0);
447449
}

jstests/repl/basic1.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,30 @@ t.update( { "b" : 3} , { $set : { "b.$" : 17 } } )
121121
block();
122122
check( "after pos 4 " );
123123

124-
125124
printjson( am.rpos.findOne() )
126125
printjson( as.rpos.findOne() )
127126

128127
//am.getSisterDB( "local" ).getCollection( "oplog.$main" ).find().limit(10).sort( { $natural : -1 } ).forEach( printjson )
129128

129+
130+
t = am.b;
131+
t.update( { "_id" : "fun"}, { $inc : {"a.b.c.x" : 6743} } , true, false)
132+
block()
133+
check( "b 1" );
134+
135+
t.update( { "_id" : "fun"}, { $inc : {"a.b.c.x" : 5} } , true, false)
136+
block()
137+
check( "b 2" );
138+
139+
t.update( { "_id" : "fun"}, { $inc : {"a.b.c.x" : 100, "a.b.c.y" : 911} } , true, false)
140+
block()
141+
assert.eq( { _id : "fun" , a : { b : { c : { x : 6848 , y : 911 } } } } , as.b.findOne() , "b 3" );
142+
//printjson( t.findOne() )
143+
//printjson( as.b.findOne() )
144+
//am.getSisterDB( "local" ).getCollection( "oplog.$main" ).find().sort( { $natural : -1 } ).limit(3).forEach( printjson )
145+
check( "b 4" );
146+
147+
130148
rt.stop();
131149

132150

0 commit comments

Comments
 (0)