Django and Mongoengine Austin Gross [email_address] http://loc-cit.com
Mongoengine Active on GitHub Most popular MongoDB ORM   for Python (so common gotchas are easily googled) Django-like "Document" classes Integrated with Django API Sessions, Authentication, and Storage Can be used without Django
How does it work? Cf. screencast on setting up "Mumblr" at  montylounge . Search for "Integrating MongoDB and Django" Document schemas defined in a file of your choosing; they inherit from type "Document" subclasses will be stored in the same collection Call  mongoengine.connect(dbname)  in  settings.py
Schemas Support for dynamically-schema'd Documents is in development! Otherwise, familiar look and feel But no JOINs: for high performance, embedding documents recommended Lists of "Embedded Documents" recommended in appropriate cases Otherwise,  ListField(ReferenceField(target_doc))
Schemas II But Embeds can't be nested manageably! With MongoDB's $ operator, it's impossible to update a single comment embedded in a reply embedded in a thread. At best, retrieve and change  all  comments and set them all at once. Embedded Documents in Mongoengine don't work like Django models, even though MongoDB encourages Embeds as an alternative to References. No .save() method--in fact, no methods at all; can only be updated by .update_one() on the parent document. Still, manageable for one layer
Django Functionality Auth, Sessions, and File serving all fine More complicated: Caching Generic views Testing ModelForms
Caching Try django-mongodb-cache? (I haven't)
Testing Before unit tests, call: mongoengine.connect('unit-tests') ...That's it! Import your models and testing works as expected on test database 'unit-tests'
ModelForms: a lot of work Might be more complicated. A GitHub project exists: "django-mongoforms" It's buggy and the last commit was in March ReferenceField supported No MultipleReferenceField! No custom widgets Workable, but takes work Would be pretty complicated for any model we store as an Embedded Document
Generic views: easily adapted For example, in django.views.generic.create_update: document._meta.app_label  doesn't exist automatically, but can be added same for  document._meta.verbose_name ... or remove that from the view. You'll have to incorporate the mongoengine-compatible version of ModelForms, since  create_update  otherwise will try to use Django's ModelForm
Bells and Whistles Registration forms, etc. Things like Ajax-based autocomplete are available for Django, not yet for mongoengine
GitHub links Mongoengine. Try Django-mumblr for a working mongoengine application Django-mongoforms. Some branches might be more useful than the original, so cf. the network.

Django and Mongoengine

  • 1.
    Django and MongoengineAustin Gross [email_address] http://loc-cit.com
  • 2.
    Mongoengine Active onGitHub Most popular MongoDB ORM   for Python (so common gotchas are easily googled) Django-like "Document" classes Integrated with Django API Sessions, Authentication, and Storage Can be used without Django
  • 3.
    How does itwork? Cf. screencast on setting up "Mumblr" at montylounge . Search for "Integrating MongoDB and Django" Document schemas defined in a file of your choosing; they inherit from type "Document" subclasses will be stored in the same collection Call mongoengine.connect(dbname) in settings.py
  • 4.
    Schemas Support fordynamically-schema'd Documents is in development! Otherwise, familiar look and feel But no JOINs: for high performance, embedding documents recommended Lists of "Embedded Documents" recommended in appropriate cases Otherwise, ListField(ReferenceField(target_doc))
  • 5.
    Schemas II ButEmbeds can't be nested manageably! With MongoDB's $ operator, it's impossible to update a single comment embedded in a reply embedded in a thread. At best, retrieve and change  all  comments and set them all at once. Embedded Documents in Mongoengine don't work like Django models, even though MongoDB encourages Embeds as an alternative to References. No .save() method--in fact, no methods at all; can only be updated by .update_one() on the parent document. Still, manageable for one layer
  • 6.
    Django Functionality Auth,Sessions, and File serving all fine More complicated: Caching Generic views Testing ModelForms
  • 7.
  • 8.
    Testing Before unittests, call: mongoengine.connect('unit-tests') ...That's it! Import your models and testing works as expected on test database 'unit-tests'
  • 9.
    ModelForms: a lotof work Might be more complicated. A GitHub project exists: "django-mongoforms" It's buggy and the last commit was in March ReferenceField supported No MultipleReferenceField! No custom widgets Workable, but takes work Would be pretty complicated for any model we store as an Embedded Document
  • 10.
    Generic views: easilyadapted For example, in django.views.generic.create_update: document._meta.app_label doesn't exist automatically, but can be added same for document._meta.verbose_name ... or remove that from the view. You'll have to incorporate the mongoengine-compatible version of ModelForms, since create_update  otherwise will try to use Django's ModelForm
  • 11.
    Bells and WhistlesRegistration forms, etc. Things like Ajax-based autocomplete are available for Django, not yet for mongoengine
  • 12.
    GitHub links Mongoengine.Try Django-mumblr for a working mongoengine application Django-mongoforms. Some branches might be more useful than the original, so cf. the network.