summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authoragirbal <antoine@10gen.com>2010-12-17 00:11:24 -0800
committeragirbal <antoine@10gen.com>2010-12-17 00:12:16 -0800
commit28904fa7ae991355a1043da387328ad98bb0ac84 (patch)
tree0c02aa5fa8b67fb541684be0c1c202c453db4617 /shell
parent7512156d5a49af0bce17abe483210d56f08caf08 (diff)
downloadmongo-28904fa7ae991355a1043da387328ad98bb0ac84.tar.gz
[SERVER-1988]: Upsert allows inserting records with dots in key names
Diffstat (limited to 'shell')
-rw-r--r--shell/collection.js12
-rw-r--r--shell/mongo_vstudio.cpp10
2 files changed, 21 insertions, 1 deletions
diff --git a/shell/collection.js b/shell/collection.js
index 174b70ae322..0f832229015 100644
--- a/shell/collection.js
+++ b/shell/collection.js
@@ -180,7 +180,17 @@ DBCollection.prototype.remove = function( t , justOne ){
DBCollection.prototype.update = function( query , obj , upsert , multi ){
assert( query , "need a query" );
assert( obj , "need an object" );
- this._validateObject( obj );
+
+ var firstKey = null;
+ for (var k in obj) { firstKey = k; break; }
+
+ if (firstKey != null && firstKey[0] == '$') {
+ // for mods we only validate partially, for example keys may have dots
+ this._validateObject( obj );
+ } else {
+ // we're basically inserting a brand new object, do full validation
+ this._validateForStorage( obj );
+ }
this._mongo.update( this._fullName , query , obj , upsert ? true : false , multi ? true : false );
}
diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp
index 449d2c2e4bc..fccee83a5f7 100644
--- a/shell/mongo_vstudio.cpp
+++ b/shell/mongo_vstudio.cpp
@@ -2928,7 +2928,17 @@ const StringData _jscode_raw_collection =
"DBCollection.prototype.update = function( query , obj , upsert , multi ){\n"
"assert( query , \"need a query\" );\n"
"assert( obj , \"need an object\" );\n"
+"\n"
+"var firstKey = null;\n"
+"for (var k in obj) { firstKey = k; break; }\n"
+"\n"
+"if (firstKey != null && firstKey[0] == '$') {\n"
+"// for mods we only validate partially, for example keys may have dots\n"
"this._validateObject( obj );\n"
+"} else {\n"
+"// we're basically inserting a brand new object, do full validation\n"
+"this._validateForStorage( obj );\n"
+"}\n"
"this._mongo.update( this._fullName , query , obj , upsert ? true : false , multi ? true : false );\n"
"}\n"
"\n"