0

I have a Flask app that I am deploying to Heroku that I want to connect to a MongoDB instance using mongoengine. It looks like this:

if __name__ == '__main__':
    mongo_host = os.environ.get('MONGODB_URI')
    connect(alias='default', host=mongo_host)
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port, debug=True)

I'm able to connect to this instance on localhost but when I try to run it on Heroku I get this error: mongoengine.connection.MongoEngineConnectionError: You have not defined a default connection

What am I doing wrong?

UPDATE:

I'm using mongoengine version 0.13.0 on both localhost and Heroku deploy

stoebelj
  • 1,536
  • 2
  • 14
  • 31
  • Could you please tell us the version of mongoengine in your local machine and on Heroku server? – Aliakbar Abbasi Sep 10 '17 at 11:03
  • @abilinx `mongoengine==0.13.0` – stoebelj Sep 10 '17 at 15:54
  • You might want to try [Flask-Mongoengine](http://docs.mongoengine.org/projects/flask-mongoengine/en/latest/) . Using this will take care of the default connection once you initialize the mongoengine with the flask app context, as explained in the documentation. – Sreenadh T C Sep 16 '17 at 17:59

0 Answers0