0π
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.
21π
I have not tested this in-depth, but so far it worked for me:
mongoengine.connect('yourdb', alias='default')
- Django Nested Groups: Groups in Groups
- What is the proper way of testing throttling in DRF?
- Using django with postman {"detail":"CSRF Failed: CSRF token missing or incorrect."}
7π
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π
You need to specify the mongodb database name and not _MONGODB_NAME. You also need to comment the DATABASE settings in the django.
#Database connection
class ConnectionError(Exception):
pass
from mongoengine import connect
try:
connected = connect("blogDatabase", "localhost")
if connected:
print("Mongoengine is connected")
except ConnectionError:
raise ConnectionError
- How to test coverage properly with Django + Nose
- Django global variable
- Updating context data in FormView form_valid method?
- Can't save a form in Django (object has no attribute 'save')