title: How to connect to Mongolab from Flask MongoEngine on Heroku?
body: <p>I've got a website built in the Python <a href="http://flask.pocoo.org/" rel="nofollow">Flask</a> framework which I now want to deploy to <a href="http://heroku.com/" rel="nofollow">Heroku</a>. In my website I use <a href="http://www.mongodb.org/" rel="nofollow">MongoDB</a> with the <a href="http://mongoengine.org/" rel="nofollow">MongoEngine ORM</a>. In my config.py file I've currently got mongoDB defined as follows:</p>
  
  <pre><code>MONGODB_SETTINGS = {
      'db': 'mymongodb'
  }
  </code></pre>
  
  <p>In my <code>__init__.py</code> I then load the config file:</p>
  
  <pre><code>app.config.from_object('config')
  mongoDb = MongoEngine(app)
  </code></pre>
  
  <p>This works when running the DB locally on my laptop. So as suggested <a href="https://devcenter.heroku.com/articles/mongolab#getting-your-connection-uri" rel="nofollow">here</a> I run  <code>heroku config | grep MONGOLAB_URI</code> to get the uri. As <a href="http://docs.mongoengine.org/guide/connecting.html" rel="nofollow">suggested here</a> I then tried pasting that uri in the current code (I x-ed the username and password away):</p>
  
  <pre><code>MONGODB_SETTINGS = {
      'host': 'mongodb://heroku_appxxxxxxx:xxxxxxxx@ds0123456.mongolab.com:12345/heroku_appxxxxx'
  }
  </code></pre>
  
  <p>After committing and pushing to heroku I still get an Application Error though. My logs give a <code>TypeError: connect() takes at least 1 argument (0 given)</code> (for full stacktrace see below). So I presume MongoEngine doesn't read the host from the MONGODB_SETTINGS, but I wouldn't know how else to do it. I checked out <a href="https://github.com/mongolab/mongodb-driver-examples/blob/master/python/pymongo_simple_example.py" rel="nofollow">the official Python example for MongoLab</a> which works with PyMongo, but it doesn't help me any further.</p>
  
  <p>Does anybody know how I can connect to Mongolab from MongoEngine? All tips are welcome!</p>
  
  <pre><code>2014-12-09T15:18:17.157377+00:00 heroku[web.1]: State changed from starting to up
  2014-12-09T15:18:17.467335+00:00 app[web.1]: [2014-12-09 15:18:17 +0000] [7] [ERROR] Exception in worker process:
  2014-12-09T15:18:17.467341+00:00 app[web.1]: Traceback (most recent call last):
  2014-12-09T15:18:17.467343+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
  2014-12-09T15:18:17.467345+00:00 app[web.1]:     worker.init_process()
  2014-12-09T15:18:17.467347+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 114, in init_process
  2014-12-09T15:18:17.467348+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
  2014-12-09T15:18:17.467350+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 66, in wsgi
  2014-12-09T15:18:17.467352+00:00 app[web.1]:     self.callable = self.load()
  2014-12-09T15:18:17.467373+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
  2014-12-09T15:18:17.467375+00:00 app[web.1]:     return self.load_wsgiapp()
  2014-12-09T15:18:17.467376+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
  2014-12-09T15:18:17.467378+00:00 app[web.1]:     return util.import_app(self.app_uri)
  2014-12-09T15:18:17.467379+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 356, in import_app
  2014-12-09T15:18:17.467381+00:00 app[web.1]:     __import__(module)
  2014-12-09T15:18:17.467382+00:00 app[web.1]:   File "/app/app/__init__.py", line 19, in &lt;module&gt;
  2014-12-09T15:18:17.467384+00:00 app[web.1]:     mongoDb = MongoEngine(app)  # Load document store (mongodb)
  2014-12-09T15:18:17.467385+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask_mongoengine/__init__.py", line 33, in __init__
  2014-12-09T15:18:17.467387+00:00 app[web.1]:     self.init_app(app)
  2014-12-09T15:18:17.467388+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask_mongoengine/__init__.py", line 66, in init_app
  2014-12-09T15:18:17.467389+00:00 app[web.1]:     self.connection = mongoengine.connect(**conn_settings)
  2014-12-09T15:18:17.467391+00:00 app[web.1]: TypeError: connect() takes at least 1 argument (0 given)
  </code></pre>