From 643cfc0888835f9d5f780c1080ec5a3cc2984bb5 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Wed, 24 Jun 2009 14:49:50 -0400 Subject: nice error when trying to save DBQuery --- shell/collection.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'shell/collection.js') diff --git a/shell/collection.js b/shell/collection.js index 88d25c9f269..1601bc0f640 100644 --- a/shell/collection.js +++ b/shell/collection.js @@ -86,13 +86,21 @@ DBCollection.prototype._massageObject = function( q ){ } + +DBCollection.prototype._validateObject = function( o ){ + if ( o._ensureSpecial && o._checkModify ) + throw "can't save a DBQuery object"; +} + DBCollection.prototype._validateForStorage = function( o ){ + this._validateObject( o ); for ( var k in o ){ if ( k.indexOf( "." ) >= 0 ) throw "can't have . in field names [" + k + "]" ; } } + DBCollection.prototype.find = function( query , fields , limit , skip ){ return new DBQuery( this._mongo , this._db , this , this._fullName , this._massageObject( query ) , fields , limit , skip ); @@ -123,6 +131,7 @@ DBCollection.prototype.remove = function( t ){ DBCollection.prototype.update = function( query , obj , upsert ){ assert( query , "need a query" ); assert( obj , "need an object" ); + this._validateObject( obj ); return this._mongo.update( this._fullName , query , obj , upsert ? true : false ); } -- cgit v1.2.1