diff options
author | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
commit | 5d342a758c6095b4d30aba0750b54f13b8916f51 (patch) | |
tree | 762e9aa84781f5e3b96db2c02d356c29cf0217c0 /shell/collection.js | |
parent | cbe2d992e9cd1ea66af9fa91df006106775d3073 (diff) | |
download | mongodb-5d342a758c6095b4d30aba0750b54f13b8916f51.tar.gz |
Imported Upstream version 2.0.0
Diffstat (limited to 'shell/collection.js')
-rw-r--r-- | shell/collection.js | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/shell/collection.js b/shell/collection.js index 8d4d4c7..1e6fe03 100644 --- a/shell/collection.js +++ b/shell/collection.js @@ -60,7 +60,7 @@ DBCollection.prototype.help = function () { print("\tdb." + shortName + ".totalIndexSize() - size in bytes of all the indexes"); print("\tdb." + shortName + ".totalSize() - storage allocated for all data and indexes"); print("\tdb." + shortName + ".update(query, object[, upsert_bool, multi_bool])"); - print("\tdb." + shortName + ".validate() - SLOW"); + print("\tdb." + shortName + ".validate( <full> ) - SLOW");; print("\tdb." + shortName + ".getShardVersion() - only for use with sharding"); return __magicNoPrint; } @@ -120,7 +120,7 @@ DBCollection.prototype._validateObject = function( o ){ throw "can't save a DBQuery object"; } -DBCollection._allowedFields = { $id : 1 , $ref : 1 }; +DBCollection._allowedFields = { $id : 1 , $ref : 1 , $db : 1 , $MinKey : 1, $MaxKey : 1 }; DBCollection.prototype._validateForStorage = function( o ){ this._validateObject( o ); @@ -374,21 +374,32 @@ DBCollection.prototype.renameCollection = function( newName , dropTarget ){ dropTarget : dropTarget } ) } -DBCollection.prototype.validate = function() { - var res = this._db.runCommand( { validate: this.getName() } ); +DBCollection.prototype.validate = function(full) { + var cmd = { validate: this.getName() }; - res.valid = false; + if (typeof(full) == 'object') // support arbitrary options here + Object.extend(cmd, full); + else + cmd.full = full; + + var res = this._db.runCommand( cmd ); + + if (typeof(res.valid) == 'undefined') { + // old-style format just put everything in a string. Now using proper fields - var raw = res.result || res.raw; + res.valid = false; - if ( raw ){ - var str = "-" + tojson( raw ); - res.valid = ! ( str.match( /exception/ ) || str.match( /corrupt/ ) ); + var raw = res.result || res.raw; - var p = /lastExtentSize:(\d+)/; - var r = p.exec( str ); - if ( r ){ - res.lastExtentSize = Number( r[1] ); + if ( raw ){ + var str = "-" + tojson( raw ); + res.valid = ! ( str.match( /exception/ ) || str.match( /corrupt/ ) ); + + var p = /lastExtentSize:(\d+)/; + var r = p.exec( str ); + if ( r ){ + res.lastExtentSize = Number( r[1] ); + } } } @@ -530,13 +541,21 @@ DBCollection.prototype.isCapped = function(){ return ( e && e.options && e.options.capped ) ? true : false; } +DBCollection.prototype._distinct = function( keyString , query ){ + return this._dbCommand( { distinct : this._shortName , key : keyString , query : query || {} } ); + if ( ! res.ok ) + throw "distinct failed: " + tojson( res ); + return res.values; +} + DBCollection.prototype.distinct = function( keyString , query ){ - var res = this._dbCommand( { distinct : this._shortName , key : keyString , query : query || {} } ); + var res = this._distinct( keyString , query ); if ( ! res.ok ) throw "distinct failed: " + tojson( res ); return res.values; } + DBCollection.prototype.group = function( params ){ params.ns = this._shortName; return this._db.group( params ); @@ -578,7 +597,8 @@ MapReduceResult.prototype.drop = function(){ */ MapReduceResult.prototype.convertToSingleObject = function(){ var z = {}; - this._coll.find().forEach( function(a){ z[a._id] = a.value; } ); + var it = this.results != null ? this.results : this._coll.find(); + it.forEach( function(a){ z[a._id] = a.value; } ); return z; } @@ -593,7 +613,7 @@ DBCollection.prototype.convertToSingleObject = function(valueField){ */ DBCollection.prototype.mapReduce = function( map , reduce , optionsOrOutString ){ var c = { mapreduce : this._shortName , map : map , reduce : reduce }; - assert( optionsOrOutString , "need to an optionsOrOutString" ) + assert( optionsOrOutString , "need to supply an optionsOrOutString" ) if ( typeof( optionsOrOutString ) == "string" ) c["out"] = optionsOrOutString; |