Skip to content

'readPreference' param in config URI was ignored in mongoengine.register_connection #1665

@kkzxak47

Description

@kkzxak47

I have a config string 'mongodb://mongodb01.test.vpc,mongodb02.test.vpc,mongodb03.test.vpc/prod?readPreference=secondaryPreferred'

it was parsed to dict below by pymongo.uri_parser.parse_uri

{'collection': None,
 'database': 'prod',
 'nodelist': [('mongodb01.test.vpc', 27017),
  ('mongodb02.test.vpc', 27017),
  ('mongodb03.test.vpc', 27017)],
 'options': {'readpreference': 'secondaryPreferred'},
 'password': None,
 'username': None}

but mongoengine only read in 3 params if I read correctly, ignored 'readpreference'

            if 'replicaset' in uri_options:
                conn_settings['replicaSet'] = uri_options['replicaset']
            if 'authsource' in uri_options:
                conn_settings['authentication_source'] = uri_options['authsource']
            if 'authmechanism' in uri_options:
                conn_settings['authentication_mechanism'] = uri_options['authmechanism']

thus made my config not functioning as I needed.

I don't know if this is a bug or a feature. To achieve my goal do I have to explicitly invoke connect(..., read_preference=secondaryPreferred)? Isn't controlling readpreference in a config string be more flexible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions