diff --git a/pymongo/collection.py b/pymongo/collection.py index affdf93d5..ba8e3f1db 100644 --- a/pymongo/collection.py +++ b/pymongo/collection.py @@ -1052,7 +1052,7 @@ class Collection(common.BaseObject): read_preference=ReadPreference.PRIMARY, indexes=[index]) except OperationFailure, exc: - if exc.code in (59, None): + if exc.code in common.COMMAND_NOT_FOUND_CODES: index["ns"] = self.__full_name self.__database.system.indexes.insert(index, manipulate=False, check_keys=False, diff --git a/pymongo/common.py b/pymongo/common.py index f246339c7..60d618d16 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -47,6 +47,14 @@ MAX_WRITE_BATCH_SIZE = 1000 MIN_SUPPORTED_WIRE_VERSION = 0 MAX_SUPPORTED_WIRE_VERSION = 2 +# mongod/s 2.6 and above return code 59 when a +# command doesn't exist. mongod versions previous +# to 2.6 and mongos 2.4.x return no error code +# when a command does exist. mongos versions previous +# to 2.4.0 return code 13390 when a command does not +# exist. +COMMAND_NOT_FOUND_CODES = (59, 13390, None) + def raise_config_error(key, dummy): """Raise ConfigurationError with the given key name.""" diff --git a/pymongo/database.py b/pymongo/database.py index f565b7260..49e0a7eb3 100644 --- a/pymongo/database.py +++ b/pymongo/database.py @@ -779,11 +779,8 @@ class Database(common.BaseObject): read_preference=ReadPreference.PRIMARY) except OperationFailure, exc: # MongoDB >= 2.5.3 requires the use of commands to manage - # users. "No such command" error didn't return an error - # code (59) before MongoDB 2.4.7 so we assume that an error - # code of None means the userInfo command doesn't exist and - # we should fall back to the legacy add user code. - if exc.code in (59, None): + # users. + if exc.code in common.COMMAND_NOT_FOUND_CODES: self._legacy_add_user(name, password, read_only, **kwargs) return raise