diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index 6fe6496..57a36f0 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -595,11 +595,16 @@ 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}, :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) - raise MongoDBError, "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i + cmd = BSON::OrderedHash.new + cmd[:validate] = name + cmd[:full] = true + doc = command(cmd, :check_response => false) + if !ok?(doc) + raise MongoDBError, "Error with validate command: #{doc.inspect}" + end + if !doc['valid'] + raise MongoDBError, "Error: invalid collection #{name}: #{doc.inspect}" + end doc end diff --git a/test/db_test.rb b/test/db_test.rb index 0154592..891dbbd 100644 --- a/test/db_test.rb +++ b/test/db_test.rb @@ -298,17 +298,13 @@ class DBTest < Test::Unit::TestCase assert_kind_of Array, info assert info.length >= 1 first = info.first - assert_kind_of String, first['info'] assert_kind_of Time, first['ts'] assert_kind_of Numeric, first['millis'] end should "validate collection" do doc = @db.validate_collection(@coll.name) - assert_not_nil doc - result = doc['result'] - assert_not_nil result - assert_match(/firstExtent/, result) + assert doc['valid'] end end