summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-02-04 18:33:59 -0500
committerAaron <aaron@10gen.com>2009-02-04 18:33:59 -0500
commit082cd621d3e5606b8e1d2562174f39e6c7d1e89d (patch)
tree364e19bd371a945f996d7e722bbc1eb60c6ba94e
parent5cb34b0b80f5a4ab64f1f346f7712403fd81b6de (diff)
downloadmongo-082cd621d3e5606b8e1d2562174f39e6c7d1e89d.tar.gz
Update with mods on embedded objects
-rw-r--r--db/query.cpp2
-rw-r--r--jstests/update3.js16
-rw-r--r--mongo.xcodeproj/project.pbxproj2
3 files changed, 19 insertions, 1 deletions
diff --git a/db/query.cpp b/db/query.cpp
index b788b67c317..143d15f4b7b 100644
--- a/db/query.cpp
+++ b/db/query.cpp
@@ -265,7 +265,7 @@ namespace mongo {
void Mod::applyMods(vector<Mod>& mods, BSONObj obj) {
for ( vector<Mod>::iterator i = mods.begin(); i != mods.end(); i++ ) {
Mod& m = *i;
- BSONElement e = obj.findElement(m.fieldName);
+ BSONElement e = obj.getFieldDotted(m.fieldName);
if ( e.isNumber() ) {
if ( m.op == INC ) {
e.setNumber( e.number() + m.getn() );
diff --git a/jstests/update3.js b/jstests/update3.js
new file mode 100644
index 00000000000..0708bff759f
--- /dev/null
+++ b/jstests/update3.js
@@ -0,0 +1,16 @@
+f = db.jstests_update3;
+
+f.drop();
+f.save( { a:1 } );
+f.update( {}, {$inc:{ a:1 }} );
+assert.eq( 2, f.findOne().a );
+
+f.drop();
+f.save( { a:{ b: 1 } } );
+f.update( {}, {$inc:{ "a.b":1 }} );
+assert.eq( 2, f.findOne().a.b );
+
+f.drop();
+f.save( { a:{ b: 1 } } );
+f.update( {}, {$set:{ "a.b":5 }} );
+assert.eq( 5, f.findOne().a.b );
diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj
index 509955c9ecf..820ee328652 100644
--- a/mongo.xcodeproj/project.pbxproj
+++ b/mongo.xcodeproj/project.pbxproj
@@ -106,6 +106,7 @@
934DD88B0EFAD23B00459CC1 /* sock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sock.h; sourceTree = "<group>"; };
934DD88D0EFAD23B00459CC1 /* unittest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unittest.h; sourceTree = "<group>"; };
934DD88E0EFAD23B00459CC1 /* util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = util.cpp; sourceTree = "<group>"; };
+ 936AB4BB0F3A5B0300D5015F /* update3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = update3.js; sourceTree = "<group>"; };
937CACE90F27BF4900C57AA6 /* socktests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = socktests.cpp; sourceTree = "<group>"; };
937D0E340F28CB070071FFA9 /* repltests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = repltests.cpp; sourceTree = "<group>"; };
937D14AB0F2A225F0071FFA9 /* nonce.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nonce.h; sourceTree = "<group>"; };
@@ -392,6 +393,7 @@
93A8D1D10F37544800C92B85 /* jstests */ = {
isa = PBXGroup;
children = (
+ 936AB4BB0F3A5B0300D5015F /* update3.js */,
93A8D8200F38FE2400C92B85 /* autoid.js */,
93A8D1D30F37544800C92B85 /* _runner.js */,
93A8D1D40F37544800C92B85 /* apitest_db.js */,