|
13 | 13 | ) |
14 | 14 |
|
15 | 15 | DEFAULT_CONNECTION_NAME = 'default-mongodb-connection' |
16 | | -if pymongo.version_tuple[0] < 3: |
17 | | - IS_PYMONGO_3 = False |
18 | | -else: |
19 | | - IS_PYMONGO_3 = True |
20 | 16 |
|
21 | 17 | _connection_settings = {} |
22 | 18 | _connections = {} |
@@ -253,18 +249,19 @@ def _resolve_settings(conn_setting, removePass=True): |
253 | 249 | username = conn_setting.get('MONGODB_USERNAME', conn_setting.get('username', None)) |
254 | 250 | password = conn_setting.get('MONGODB_PASSWORD', conn_setting.get('password', None)) |
255 | 251 |
|
256 | | - if IS_PYMONGO_3: |
| 252 | + if pymongo.version_tuple[0] < 3: |
257 | 253 | read_preference = ReadPreference.PRIMARY |
258 | 254 |
|
259 | 255 | resolved = {} |
260 | 256 | resolved['read_preference'] = read_preference |
261 | 257 | resolved['alias'] = alias |
262 | | - resolved['name'] = db |
263 | | - resolved['host'] = host |
264 | | - resolved['password'] = password |
265 | | - resolved['port'] = port |
266 | | - resolved['username'] = username |
267 | | - resolved['replicaSet'] = conn_setting.pop('replicaset', None) |
| 258 | + if db: resolved['name'] = db |
| 259 | + if host: resolved['host'] = host |
| 260 | + if password: resolved['password'] = password |
| 261 | + if port: resolved['port'] = port |
| 262 | + if username: resolved['username'] = username |
| 263 | + if conn_setting.pop('replicaset', None): |
| 264 | + resolved['replicaSet'] = conn_setting.pop('replicaset', None) |
268 | 265 |
|
269 | 266 | host = resolved['host'] |
270 | 267 | # Handle uri style connections |
|
0 commit comments