add DB#last_status method
This commit is contained in:
parent
f1bf2eb4d6
commit
79e76be9df
|
@ -267,22 +267,19 @@ module Mongo
|
|||
|
||||
# Returns the error message from the most recently executed database
|
||||
# operation for this connection, or +nil+ if there was no error.
|
||||
#
|
||||
# Note: as of this writing, errors are only detected on the db server
|
||||
# for certain kinds of operations (writes). The plan is to change this
|
||||
# so that all operations will set the error if needed.
|
||||
def error
|
||||
doc = db_command(:getlasterror => 1)
|
||||
raise "error retrieving last error: #{doc}" unless ok?(doc)
|
||||
doc['err']
|
||||
end
|
||||
|
||||
# Get status information from the last operation on this connection.
|
||||
def last_status
|
||||
db_command(:getlasterror => 1)
|
||||
end
|
||||
|
||||
# Returns +true+ if an error was caused by the most recently executed
|
||||
# database operation.
|
||||
#
|
||||
# Note: as of this writing, errors are only detected on the db server
|
||||
# for certain kinds of operations (writes). The plan is to change this
|
||||
# so that all operations will set the error if needed.
|
||||
def error?
|
||||
error != nil
|
||||
end
|
||||
|
|
|
@ -176,6 +176,17 @@ class DBTest < Test::Unit::TestCase
|
|||
assert_nil @@db.previous_error
|
||||
end
|
||||
|
||||
def test_last_status
|
||||
@@db['test'].clear
|
||||
@@db['test'].save("i" => 1)
|
||||
|
||||
@@db['test'].update({"i" => 1}, {"$set" => {"i" => 2}})
|
||||
assert @@db.last_status()["updatedExisting"]
|
||||
|
||||
@@db['test'].update({"i" => 1}, {"$set" => {"i" => 500}})
|
||||
assert !@@db.last_status()["updatedExisting"]
|
||||
end
|
||||
|
||||
def test_text_port_number
|
||||
db = DB.new('ruby-mongo-test', [[@@host, @@port.to_s]])
|
||||
# If there is no error, all is well
|
||||
|
|
Loading…
Reference in New Issue