hmarr/mongoengine — Issue #390: Proposal to allow transparent passing of params into pymongo
Author: Amorano
Created: 2011-12-10 03:13:59+00:00
State: open

I apologize I have not simply branched and submitted, I am more a mercurial user.

In connection.py, I propose the following code change for the register_connection function:

```python
def register_connection(alias, name, host='localhost', port=27017,
is_slave=False, read_preference=False, slaves=None,
username=None, password=None, **kwargs):
"""Add a connection.

:param alias: the name that will be used to refer to this connection
throughout MongoEngine
:param name: the name of the specific database to use
:param host: the host name of the :program:`mongod` instance to connect to
:param port: the port that the :program:`mongod` instance is running on
:param is_slave: whether the connection can act as a slave ** Depreciated pymongo 2.0.1+
:param read_preference: The read preference for the collection ** Added pymongo 2.1
:param slaves: a list of aliases of slave connections; each of these must
be a registered connection that has :attr:`is_slave` set to ``True``
:param username: username to authenticate with
:param password: password to authenticate with
:param kwargs: allow ad-hoc parameters to be passed into the pymongo driver

"""
global _connection_settings
_connection_settings[alias] = {
'name': name,
'host': host,
'port': port,
'is_slave': is_slave,
'slaves': slaves or [],
'username': username,
'password': password,
'read_preference': read_preference
}
for k,v in kwargs.iteritems():
_connection_settings[alias][k] = v
```
This allows passing any/all other parameters into pymongo (like replicaSet, safe, etc...)