The problem arises:
Mongoengine is an object-document mapper (Object-document Mapper) that can manipulate the MongoDB database. In the process of using Mongodb+django to implement a small web site for data entry systems, the Mongoengine cannot call MongoDB from Python, and the following error occurred in the Connect () database step:
>>> from mongoengine import connect
>>> connect(‘healthmanager‘)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/python2.7/lib/python2.7/site-packages/mongoengine/connection.py", line 164, in connect
return get_connection(alias)
File "/usr/local/python2.7/lib/python2.7/site-packages/mongoengine/connection.py", line 126, in get_connection
raise ConnectionError("Cannot connect to database %s :\n%s" % (alias, e))
ConnectionError: Cannot connect to database default :
False is not a read preference.
The reason for this is that through the "Pip install Mongoengine" The installation of the Mongoengine is 0.9.0 version, and the command pymongo-3.0.2 module dependencies are also installed, and pymongo-3.0.2 and mongoengine-0.9.0 there is a compatibility problem, resulting in the default database cannot connect successfully.
>>> import pymongo
>>> pymongo.version
‘3.0.2‘
In addition, CentOS 6.5 under the "Pip Install Pymongo" installed Pymongo 3.0.2 version, and Mongoengine as an extension package for Pymongo, is not installed. Therefore, when using Mongoengine, after installing mongoengine, you need to reduce the Pymongo version to less than 3.0. 、
Workaround:
=> PIP install mongoengine # install mongoengine
=> PIP uninstall pymongo # uninstall pymongo-3.0.2
=> PIP install pymongo==2.8 # install pymongo-2.8
Reconnect Connect:
>>> from mongoengine import connect
>>> connect(‘healthmanager‘)
MongoClient(‘localhost‘, 27017)
OK, problem solving!!!
Mongoengine connection Error: "False is not a read preference" workaround