summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-05-27 11:45:24 -0400
committerEliot Horowitz <eliot@10gen.com>2010-05-27 11:45:24 -0400
commit5bf66857bc03076771077a92da2e05efafc36412 (patch)
tree1ce70023c3dfab3789f4e249c0d5a3cb6598566b
parent637dbb7bb2f66de95ab38b0b1712f8fc7ef98263 (diff)
downloadmongo-5bf66857bc03076771077a92da2e05efafc36412.tar.gz
fix repl $inc issue SERVER-1161
-rw-r--r--db/update.cpp2
-rw-r--r--db/update.h12
-rw-r--r--jstests/repl/basic1.js20
3 files changed, 27 insertions, 7 deletions
diff --git a/db/update.cpp b/db/update.cpp
index 6b9df9c5b45..6dcfc785e28 100644
--- a/db/update.cpp
+++ b/db/update.cpp
@@ -67,7 +67,7 @@ namespace mongo {
ms.incint = elt.numberInt() + in.numberInt();
}
- ms.appendIncValue( bb );
+ ms.appendIncValue( bb , false );
}
template< class Builder >
diff --git a/db/update.h b/db/update.h
index 3c4daabaeae..bfec7cd44b6 100644
--- a/db/update.h
+++ b/db/update.h
@@ -413,7 +413,7 @@ namespace mongo {
void appendForOpLog( BSONObjBuilder& b ) const {
if ( incType ){
BSONObjBuilder bb( b.subobjStart( "$set" ) );
- appendIncValue( bb );
+ appendIncValue( bb , true );
bb.done();
return;
}
@@ -434,14 +434,16 @@ namespace mongo {
}
template< class Builder >
- void appendIncValue( Builder& b ) const {
+ void appendIncValue( Builder& b , bool useFullName ) const {
+ const char * n = useFullName ? m->fieldName : m->shortFieldName;
+
switch ( incType ){
case NumberDouble:
- b.append( m->shortFieldName , incdouble ); break;
+ b.append( n , incdouble ); break;
case NumberLong:
- b.append( m->shortFieldName , inclong ); break;
+ b.append( n , inclong ); break;
case NumberInt:
- b.append( m->shortFieldName , incint ); break;
+ b.append( n , incint ); break;
default:
assert(0);
}
diff --git a/jstests/repl/basic1.js b/jstests/repl/basic1.js
index 594ba07643f..0af26ac2225 100644
--- a/jstests/repl/basic1.js
+++ b/jstests/repl/basic1.js
@@ -121,12 +121,30 @@ t.update( { "b" : 3} , { $set : { "b.$" : 17 } } )
block();
check( "after pos 4 " );
-
printjson( am.rpos.findOne() )
printjson( as.rpos.findOne() )
//am.getSisterDB( "local" ).getCollection( "oplog.$main" ).find().limit(10).sort( { $natural : -1 } ).forEach( printjson )
+
+t = am.b;
+t.update( { "_id" : "fun"}, { $inc : {"a.b.c.x" : 6743} } , true, false)
+block()
+check( "b 1" );
+
+t.update( { "_id" : "fun"}, { $inc : {"a.b.c.x" : 5} } , true, false)
+block()
+check( "b 2" );
+
+t.update( { "_id" : "fun"}, { $inc : {"a.b.c.x" : 100, "a.b.c.y" : 911} } , true, false)
+block()
+assert.eq( { _id : "fun" , a : { b : { c : { x : 6848 , y : 911 } } } } , as.b.findOne() , "b 3" );
+//printjson( t.findOne() )
+//printjson( as.b.findOne() )
+//am.getSisterDB( "local" ).getCollection( "oplog.$main" ).find().sort( { $natural : -1 } ).limit(3).forEach( printjson )
+check( "b 4" );
+
+
rt.stop();