minor: fixes for db commands with new DB#command checking response
This commit is contained in:
parent
e9de3e56ea
commit
f1f0c87b3b
|
@ -326,7 +326,7 @@ module Mongo
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def error?
|
def error?
|
||||||
error != nil
|
get_last_error['err'] != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the most recent error to have occured on this database.
|
# Get the most recent error to have occured on this database.
|
||||||
|
@ -379,10 +379,9 @@ module Mongo
|
||||||
|
|
||||||
oh = BSON::OrderedHash.new
|
oh = BSON::OrderedHash.new
|
||||||
oh[:$eval] = code
|
oh[:$eval] = code
|
||||||
oh[:args] = args
|
oh[:args] = args
|
||||||
doc = command(oh)
|
doc = command(oh)
|
||||||
return doc['retval'] if ok?(doc)
|
doc['retval']
|
||||||
raise OperationFailure, "eval failed: #{doc['errmsg']}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rename a collection.
|
# Rename a collection.
|
||||||
|
@ -397,7 +396,7 @@ module Mongo
|
||||||
oh = BSON::OrderedHash.new
|
oh = BSON::OrderedHash.new
|
||||||
oh[:renameCollection] = "#{@name}.#{from}"
|
oh[:renameCollection] = "#{@name}.#{from}"
|
||||||
oh[:to] = "#{@name}.#{to}"
|
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}")
|
ok?(doc) || raise(MongoDBError, "Error renaming collection: #{doc.inspect}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -434,7 +433,6 @@ module Mongo
|
||||||
info
|
info
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Return stats on this database. Uses MongoDB's dbstats command.
|
# Return stats on this database. Uses MongoDB's dbstats command.
|
||||||
#
|
#
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
|
@ -530,7 +528,7 @@ module Mongo
|
||||||
def profiling_level
|
def profiling_level
|
||||||
oh = BSON::OrderedHash.new
|
oh = BSON::OrderedHash.new
|
||||||
oh[:profile] = -1
|
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)
|
raise "Error with profile command: #{doc.inspect}" unless ok?(doc) && doc['was'].kind_of?(Numeric)
|
||||||
case doc['was'].to_i
|
case doc['was'].to_i
|
||||||
when 0
|
when 0
|
||||||
|
@ -560,7 +558,7 @@ module Mongo
|
||||||
else
|
else
|
||||||
raise "Error: illegal profiling level value #{level}"
|
raise "Error: illegal profiling level value #{level}"
|
||||||
end
|
end
|
||||||
doc = command(oh)
|
doc = command(oh, :check_response => false)
|
||||||
ok?(doc) || raise(MongoDBError, "Error with profile command: #{doc.inspect}")
|
ok?(doc) || raise(MongoDBError, "Error with profile command: #{doc.inspect}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -580,7 +578,7 @@ module Mongo
|
||||||
# @raise [MongoDBError] if the command fails or there's a problem with the validation
|
# @raise [MongoDBError] if the command fails or there's a problem with the validation
|
||||||
# data, or if the collection is invalid.
|
# data, or if the collection is invalid.
|
||||||
def validate_collection(name)
|
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)
|
raise MongoDBError, "Error with validate command: #{doc.inspect}" unless ok?(doc)
|
||||||
result = doc['result']
|
result = doc['result']
|
||||||
raise MongoDBError, "Error with validation data: #{doc.inspect}" unless result.kind_of?(String)
|
raise MongoDBError, "Error with validation data: #{doc.inspect}" unless result.kind_of?(String)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
$:.unshift '.'
|
||||||
require 'test/test_helper'
|
require 'test/test_helper'
|
||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
|
@ -238,6 +239,11 @@ class DBTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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"
|
if @@version >= "1.3.5"
|
||||||
def test_db_stats
|
def test_db_stats
|
||||||
stats = @@db.stats
|
stats = @@db.stats
|
||||||
|
|
Loading…
Reference in New Issue