diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index 6398ebb..7421f96 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -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 diff --git a/test/test_db.rb b/test/test_db.rb index d5dfe28..3ae2033 100644 --- a/test/test_db.rb +++ b/test/test_db.rb @@ -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