I am following tumbleblog application here
my __init__.py
:
from flask import Flask
from flask.ext.mongoengine import MongoEngine
app = Flask(__name__)
app.config["MONGODB_SETTINGS"] = {'DB': "sencha_web_service", 'username': "<username>", "password": "<password>"}
app.config["SECRET_KEY"] = "KeepThisS3cr3t"
db = MongoEngine(app)
if __name__ == '__main__':
app.run()
I get the error:
mongoengine.connection.ConnectionError: Cannot connect to database default :
False is not a read preference.
I tried passing in "alias"="default"
in app.config["MONGODB_SETTINGS"]
but still getting the same error.
In your MONGODB_SETTINGS dictionary, the key for the database name should be 'db', not 'DB' (i.e. all lowercase).
The error you're getting is because the MongoEngine extension cannot find the 'db' entry in your configuration, and so uses 'default' as the database name.
Edit
Upon further inspection, it seems this is a bug somewhere in (Flask-)MongoEngine (or possible pymongo) where the default value of read_preference in mongoengine.connect is False instead of an actual read preference, and is not transformed to the actual default in pymongo
If you add
from pymongo import read_preferences
to your imports and
'read_preference': read_preferences.ReadPreference.PRIMARY
to your config dictionary, it should work (that's the default read_preference in pymongo)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With