1

I'm using django non-rel with mongodb backend. The docs are clear on how to connect to a single host, however I would like to connect to all hosts in a replica set.

Is it possible to do so?

How would the the DATABASES element in settings.py look like for a connection string such as this:

mongodb://db1.example.net,db2.example.net:2500/?replicaSet=test
odedfos
  • 4,491
  • 3
  • 30
  • 42

2 Answers2

1

There is an open issue for this in the mongodb-engine project.

https://github.com/django-nonrel/mongodb-engine/pull/170#issuecomment-42406797

From the comments, this is how it should be done:

DATABASES = {

    'default': {
        'ENGINE': 'django_mongodb_engine', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'dbname',                  # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': 'mongodb://mongodb1.domain.com:27107, mongodb2.domain.com:27017/?replicaSet=replicaname',
    },
}

Update:

This has been verified to work on the main branch:

git+https://github.com/django-nonrel/mongodb-engine

odedfos
  • 4,491
  • 3
  • 30
  • 42
0

I have looked into this issue and unfortunately this is currently not possible but I have pulled a feature request to try and get this implemented in the future release.

Currently you will have to connect to each DB separately but you could look at async connections or background tasks to speed up application performance.

Dean Meehan
  • 2,511
  • 22
  • 36
  • I don't see how connecting to each DB separately helps me here in context of the django non-rel. Please explain. Also, application performance is not the issue here, but rather a robust connection to the replica set. Could you provide a link to the feature request? – odedfos Mar 24 '14 at 12:13