Skip to content

Commit 5ddbf4b

Browse files
committed
RUBY-755 Add in missing command not found code for mongos
1 parent a702d01 commit 5ddbf4b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

lib/mongo.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ module ErrorCode # MongoDB Core Server src/mongo/base/error_codes.err
6262
BAD_VALUE = 2
6363
UNKNOWN_ERROR = 8
6464
INVALID_BSON = 22
65-
COMMAND_NOT_FOUND = 59
6665
WRITE_CONCERN_FAILED = 64
6766
MULTIPLE_ERRORS_OCCURRED = 65
67+
68+
# mongod/s 2.6 and above return code 59 when a command doesn't exist.
69+
# mongod versions previous to 2.6 and mongos 2.4.x return no error code
70+
# when a command does exist.
71+
# mongos versions previous to 2.4.0 return code 13390 when a command
72+
# does not exist.
73+
COMMAND_NOT_FOUND_CODES = [nil, 59, 13390]
6874
end
6975
end
7076

lib/mongo/collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ def generate_indexes(field_spec, name, opts)
11301130
cmd = BSON::OrderedHash[:createIndexes, @name, :indexes, [selector]]
11311131
@db.command(cmd)
11321132
rescue Mongo::OperationFailure => ex
1133-
if ex.error_code == Mongo::ErrorCode::COMMAND_NOT_FOUND || ex.error_code.nil?
1133+
if Mongo::ErrorCode::COMMAND_NOT_FOUND_CODES.include?(ex.error_code)
11341134
selector[:ns] = "#{@db.name}.#{@name}"
11351135
send_write(:insert, nil, selector, false, {:w => 1}, Mongo::DB::SYSTEM_INDEX_COLLECTION)
11361136
else

lib/mongo/db.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def add_user(username, password=nil, read_only=false, opts={})
225225
# MongoDB 2.4.7 so we assume that a nil error code means the usersInfo
226226
# command doesn't exist and we should fall back to the legacy add user code.
227227
rescue OperationFailure => ex
228-
raise ex unless ex.error_code == Mongo::ErrorCode::COMMAND_NOT_FOUND || ex.error_code.nil?
228+
raise ex unless Mongo::ErrorCode::COMMAND_NOT_FOUND_CODES.include?(ex.error_code)
229229
return legacy_add_user(username, password, read_only, opts)
230230
end
231231

@@ -246,7 +246,7 @@ def remove_user(username)
246246
begin
247247
command(:dropUser => username)
248248
rescue OperationFailure => ex
249-
raise ex unless ex.error_code == Mongo::ErrorCode::COMMAND_NOT_FOUND || ex.error_code.nil?
249+
raise ex unless Mongo::ErrorCode::COMMAND_NOT_FOUND_CODES.include?(ex.error_code)
250250
response = self[SYSTEM_USER_COLLECTION].remove({:user => username}, :w => 1)
251251
response.key?('n') && response['n'] > 0 ? response : false
252252
end

0 commit comments

Comments
 (0)