Mongoengine connection Error: "False is not a read preference" workaround

Source: Internet
Author: User



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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.