summaryrefslogtreecommitdiff
path: root/shell/collection.js
diff options
context:
space:
mode:
authorMike Dirolf <mike@10gen.com>2009-07-21 15:08:45 -0400
committerMike Dirolf <mike@10gen.com>2009-07-21 15:08:45 -0400
commit3e637e9c7c12324b74d67fd86c2b449dea8bb0ba (patch)
tree2071f58f0b3d022f9726d6fb516ccd21a5d623cf /shell/collection.js
parentc7b0dcfed332e15f61d60cebc3aad713be701336 (diff)
downloadmongo-3e637e9c7c12324b74d67fd86c2b449dea8bb0ba.tar.gz
shell cannot insert key names starting with $ or containing . (including embedded documents)
Diffstat (limited to 'shell/collection.js')
-rw-r--r--shell/collection.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/shell/collection.js b/shell/collection.js
index 85cd90a38f6..f394c37f816 100644
--- a/shell/collection.js
+++ b/shell/collection.js
@@ -95,10 +95,19 @@ DBCollection.prototype._validateObject = function( o ){
DBCollection.prototype._validateForStorage = function( o ){
this._validateObject( o );
for ( var k in o ){
- if ( k.indexOf( "." ) >= 0 )
+ if ( k.indexOf( "." ) >= 0 ) {
throw "can't have . in field names [" + k + "]" ;
+ }
+
+ if ( k.indexOf( "$" ) == 0 ) {
+ throw "field names cannot start with $ [" + k + "]" ;
+ }
+
+ if ( o[k] !== null && typeof( o[k] ) === "object" ) {
+ this._validateForStorage( o[k] );
+ }
}
-}
+};
DBCollection.prototype.find = function( query , fields , limit , skip ){
@@ -117,10 +126,12 @@ DBCollection.prototype.findOne = function( query , fields ){
return ret;
}
-DBCollection.prototype.insert = function( obj ){
+DBCollection.prototype.insert = function( obj , _allow_dot ){
if ( ! obj )
throw "no object!";
- this._validateForStorage( obj );
+ if ( ! _allow_dot ) {
+ this._validateForStorage( obj );
+ }
return this._mongo.insert( this._fullName , obj );
}
@@ -183,7 +194,7 @@ DBCollection.prototype._indexSpec = function( keys, options ) {
DBCollection.prototype.createIndex = function( keys , options ){
var o = this._indexSpec( keys, options );
- this._db.getCollection( "system.indexes" ).insert( o );
+ this._db.getCollection( "system.indexes" ).insert( o , true );
}
DBCollection.prototype.ensureIndex = function( keys , options ){