1

OK.. i am starting a project in django 1.4 and i want MongoDB as my backend. after a half a day of google search, i figured out that mongoengine is a best option(as it is an active project and provides a django like orm)

Now the problem is 1. I cant find any good step-by-step setup guide to integrate mongoengine with a django project.

  1. I understand, using mongoengine means that i am replacing django orm and there is no need to do syncdb. now this project have a multi-tenant architecture (*.domain.com) which i am gonna resolve using a middleware..also a considerable part of this project will work on django admin. Question: will replacing django orm with mongoengine going to affect django admin and other operations(such as middleware, authentication etc.) ?

I am open to suggestions and criticism as well.

Manoj hans
  • 1,705
  • 3
  • 11
  • 8
  • 1
    Suggestion: don't use MongoDB as backend for Django. Use it separately but let Django use a relational DB. – Simeon Visser Dec 10 '13 at 11:31
  • the app kind of have an evolving data scheme... so have no other option but to use noSQL. – Manoj hans Dec 10 '13 at 11:37
  • You can easily change your (relational) models and migrate. It is unusual not to. Can you explain more what you mean by the "evolving data scheme"? – YXD Dec 10 '13 at 11:39
  • You can also have both databases powering the app; there's no need to complicate your Django setup unnecessarily. – Simeon Visser Dec 10 '13 at 11:40
  • yeah.. there is a part where user defines the form structure(add/delete form fields). so different users can have different form configuration and data submitted by these forms will have scheme eg. user 1 submits (name, contact) whereas user 2 submits (name, contact, address) – Manoj hans Dec 10 '13 at 11:42
  • Even if there is a way to replace Django Admin with something else? That would do a trick i guess.. – Manoj hans Dec 11 '13 at 08:58

3 Answers3

2

Django Admin is designed to work with the Django ORM only. Using MongoEngine and no Django ORM will mean you don't get the automatic admin interface. Other middleware might use the Django ORM or be sufficiently abstracted enough to allow you to plugin MongoEngine - eg: Sessions and Authentication.

There are some helpers for Django in MongoEngine - but its by no means complete or designed to be a drop in replacement for the Django ORM.

For more information see this presentation from Django Conf Finland: http://staltz.github.io/djangoconfi-mongoengine

Ross
  • 17,861
  • 2
  • 55
  • 73
2

Just in case, situation has changed and there is a solution now for this problem, namely django-mongoadmin.

lehins
  • 9,642
  • 2
  • 35
  • 49
2

A Guide to integrating Django with MongoDB

The way to connect Django with MongoDB by adding just one line of code:

First install djongo:

pip install djongo

Then run your migrations:

manage.py make migrations
manage.py migrate

and finally add to your settings file:

DATABASES = {
   ‘default’: {
      ‘ENGINE’: ‘djongo’,
      ‘NAME’: ‘your-db-name’,
   }
}

It is as simple as that!

If you want to manipulate MongoDB using Django Admin, simply fire it up:

manage.py runserver

Goto: http://localhost:8000/admin/

Manipulate your embedded models as shown in this screenshot:

enter image description here

For more information do checkout the djongo documentation.

You should definitely consider the pros and cons of using a NEW framework (like MongoEngine) vs using inbuilt Django ORM. Do read at this tutorial before considering to adopt MongoEngine as suggested by other knowledgeable members! No offence!

Let me know if you agree with this approach in the comments :)

nesdis
  • 1,182
  • 13
  • 16
  • This looks great and I'm wondering why others haven't upvoted it. As of right now, 2018-01-24, the project seems pretty active, although not ma y GitHub stars. I'm liking this option, but it seems it hasn't gained traction yet. – nicorellius Jan 24 '18 at 14:16