I'm building a website using Flask in which I use MongoDB with the MongoEngine ORM. To go for a fresh start again I now upgraded all apt and pip packages on my ubuntu 14.04 development machine. Unfortunately this broke my connection to MongoDB:
Traceback (most recent call last):
File "./run.py", line 4, in <module>
from app import app, socketio
File "/home/kr65/beta/app/__init__.py", line 21, in <module>
mongoDb = MongoEngine(app)
File "/usr/local/lib/python2.7/dist-packages/flask_mongoengine/__init__.py", line 33, in __init__
self.init_app(app)
File "/usr/local/lib/python2.7/dist-packages/flask_mongoengine/__init__.py", line 66, in init_app
self.connection = mongoengine.connect(**conn_settings)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/connection.py", line 164, in connect
return get_connection(alias)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/connection.py", line 126, in get_connection
raise ConnectionError("Cannot connect to database %s :\n%s" % (alias, e))
mongoengine.connection.ConnectionError: Cannot connect to database default :
False is not a read preference.
I checked if MongoDB is up:
$ sudo service mongodb status
mongodb start/running, process 781
and if I could get into the interactive command line:
$ mongo
MongoDB shell version: 2.4.9
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
Tue Apr 14 09:14:10.267 [initandlisten]
Tue Apr 14 09:14:10.267 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!!
Tue Apr 14 09:14:10.267 [initandlisten]
>
I didn't change anything to the code or passwords or anything like that. I did a reboot and restarted mongoDB, but nothing works. My settings are like this:
MONGODB_SETTINGS = {
'db': 'mydatabasename'
}
and I instantiate the connection like this (which worked before):
app = Flask(__name__)
app.config.from_object('config')
mongoDb = MongoEngine(app)
Since I didn't really change anything, I'm kind of unsure where to search for a solution. Does anybody have any tips how I could solve this?
[EDIT] With the tip of @lapinkoira my MongoDB now starts up correctly, but I now get the error below while querying. Any ideas how to solve this one?
File "/home/kr65/beta/app/views/webviews.py", line 476, in getDoc
userDoc = UserDocument.objects(id=docId).first()
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 309, in first
result = queryset[0]
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 160, in __getitem__
return queryset._document._from_son(queryset._cursor[key],
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 1410, in _cursor
**self._cursor_args)
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 924, in find
return Cursor(self, *args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'snapshot'
looks like you have pymongo 3.0 installed.
Mongoengine is not yet compatible with it.
You can try fix this by
pip uninstall pymongo
pip install pymongo==2.8
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