diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index b78a914..9ed9e0c 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -326,7 +326,7 @@ module Mongo # # @return [Boolean] def error? - error != nil + get_last_error['err'] != nil end # Get the most recent error to have occured on this database. @@ -379,10 +379,9 @@ module Mongo oh = BSON::OrderedHash.new oh[:$eval] = code - oh[:args] = args + oh[:args] = args doc = command(oh) - return doc['retval'] if ok?(doc) - raise OperationFailure, "eval failed: #{doc['errmsg']}" + doc['retval'] end # Rename a collection. @@ -397,7 +396,7 @@ module Mongo oh = BSON::OrderedHash.new oh[:renameCollection] = "#{@name}.#{from}" oh[:to] = "#{@name}.#{to}" - doc = DB.new('admin', @connection).command(oh) + doc = DB.new('admin', @connection).command(oh, :check_response => false) ok?(doc) || raise(MongoDBError, "Error renaming collection: #{doc.inspect}") end @@ -434,7 +433,6 @@ module Mongo info end - # Return stats on this database. Uses MongoDB's dbstats command. # # @return [Hash] @@ -530,7 +528,7 @@ module Mongo def profiling_level oh = BSON::OrderedHash.new oh[:profile] = -1 - doc = command(oh) + doc = command(oh, :check_response => false) raise "Error with profile command: #{doc.inspect}" unless ok?(doc) && doc['was'].kind_of?(Numeric) case doc['was'].to_i when 0 @@ -560,7 +558,7 @@ module Mongo else raise "Error: illegal profiling level value #{level}" end - doc = command(oh) + doc = command(oh, :check_response => false) ok?(doc) || raise(MongoDBError, "Error with profile command: #{doc.inspect}") end @@ -580,7 +578,7 @@ module Mongo # @raise [MongoDBError] if the command fails or there's a problem with the validation # data, or if the collection is invalid. def validate_collection(name) - doc = command(:validate => name) + doc = command({:validate => name}, :check_response => false) raise MongoDBError, "Error with validate command: #{doc.inspect}" unless ok?(doc) result = doc['result'] raise MongoDBError, "Error with validation data: #{doc.inspect}" unless result.kind_of?(String) diff --git a/test/db_test.rb b/test/db_test.rb index 26adcf2..ea32295 100644 --- a/test/db_test.rb +++ b/test/db_test.rb @@ -1,3 +1,4 @@ +$:.unshift '.' require 'test/test_helper' require 'digest/md5' require 'stringio' @@ -238,6 +239,11 @@ class DBTest < Test::Unit::TestCase end end + def test_eval + @@db.eval("db.system.save({_id:'hello', value: function() { print('hello'); } })") + assert_equal 'hello', @@db['system'].find_one['_id'] + end + if @@version >= "1.3.5" def test_db_stats stats = @@db.stats