Mongoengine: ConnectionError: You have not defined a default connection

后端 未结 3 990
南笙
南笙 2020-12-19 02:34

In my new Django project I set up a MongoDb database and use mongoengine module but I can\'t properly access to dabase nore in shell no in views. \"ConnectionError: You have

相关标签:
3条回答
  • 2020-12-19 02:44

    To use django with MongoDB do not use the django package available on https://www.djangoproject.com and install other packages like mongoengine, if follow this process you will find lot of difficulties.

    Rather you need to use the no@rel version of django that has been forked from djangoproject and added MongoDB support and I am sure it will make setup process and development process lot easier.

    Follow this link to install and set up the django with MongoDB. http://django-mongodb-engine.readthedocs.org/en/latest/topics/setup.html

    One more thing you may find the error below, while setting up django.

    "*Error on Django-nonrel and MongoDB: AutoField (default primary key) values must be strings representing an ObjectId on MongoDB (got u'1' instead). Please make sure your SITE_ID contains a valid ObjectId string.*"

    Follow this link to fix.

    https://gist.github.com/ielshareef/2986459

    Please let me know if you need any more help on this.

    0 讨论(0)
  • 2020-12-19 02:53

    I have not tested this in-depth, but so far it worked for me:

    mongoengine.connect('yourdb', alias='default')

    0 讨论(0)
  • 2020-12-19 02:59

    In your settings.py file replace:

    mongoengine.connect(_MONGODB_NAME, 'localhost:27017')
    

    with the below code (notice the added 'host='):

    mongoengine.connect(_MONGODB_NAME, host='localhost:27017')
    
    0 讨论(0)
提交回复
热议问题