title: How to know current name of the database in Django?
body: <p>I'm writing tests in my django project. For now, I have two database connections:</p>
  
  <pre><code>(settings.py)
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': 'db_name'
          ...
      },
  }
  </code></pre>
  
  <p>and custom connection to MongoDB:</p>
  
  <pre><code>import sys
  from pymongo import Connection
  from pymongo.errors import ConnectionFailure
  try:
      connection = Connection(host="localhost", port=27017)
      db = connection['db_name']
      print "Connected successfully(Mongo, db_name)"
  except ConnectionFailure, e:
      sys.stderr.write("Could not connect to MongoDB: %s" % e)
      sys.exit(1)
  </code></pre>
  
  <p>and I want to know when my project is running through</p>
  
  <pre><code>python manage.py test myapp
  </code></pre>
  
  <p>Because when you run tests, django automatically create separate DB(with name like <strong>test_db_name</strong>), but in this case Mongo will still run with <strong>db_name</strong>. I tried:</p>
  
  <pre><code>import sys
  from pymongo import Connection
  from pymongo.errors import ConnectionFailure
  from django.db import connections
  
  try:
      connection = Connection(host="localhost", port=27017)
      db_name = connections['default'].settings_dict['NAME']
      db = connection[db_name]
      print "Connected successfully(Mongo, %s)" % (db_name,)
  except ConnectionFailure, e:
      sys.stderr.write("Could not connect to MongoDB: %s" % e)
      sys.exit(1)
  </code></pre>
  
  <p>but it does not work</p>