8

Working on a Django project that requires a NoSQL store and I believe I've settled on Mongo. I've seen a lot of topics that talk about Mongo and Django, but none that mentioned Django-nonrel, and I can't see why it might have been disqualified, but I have no experience with any of them.

Ideally, I'd like to preserve the SQL store for the simple things, user auth, groups, etc., and use Mongo for the bigger data.

I'd also like to have my Mongo-stored objects as classes, in a Django-ORM style, so that I can have a similar 'feel', but that isn't critical.

Lastly, do any of the above allow me to use Django's multi-database support for anything, or are all my mongo queries effectively 'out of band' from the Django ORM?

If there are any other factors I'm missing that might be important, feel free to clue me in. I know little in this arena.

bmelton
  • 982
  • 1
  • 9
  • 23
  • 3
    Yes, it is possible to work with Django and MongoDB, I have done that myself a couple of years ago. I haven't tried Django-nonrel but if you want to use SQL for simple things you should stick to the original Django. You should know by now that Django doesn't have a Mongo backend but if you want to keep the Django ORM feel you should really try [mongoengine](http://mongoengine.org/). – César May 03 '12 at 03:32
  • 1
    I second the recommendation for mongoengine. – Justin May 03 '12 at 12:51

2 Answers2

5

Django-nonrel is the way to go for Django on MongoDB. There's django-mongodb.org, but that's just built on top of Django-nonrel. There's quite a bit of mongodb activity going on the django-nonrel mailing list.

Storing your mongo classes as Django ORM objects works fine, that's the whole point.

I haven't tried using the multi-database support along with SQL. I haven't seen many people use it like that, and I suspect it most likely does not work. There's some work on moving django-nonrel to be officially part of Django 1.4, I suspect it'll work after that's complete.

Using django-nonrel for auth works ok. The main problem is many-to-many relations. The auth module uses that for per user object permissions - that doesn't work. If you don't need that, you could probably get away without using the SQL at all.

dragonx
  • 14,963
  • 27
  • 44
  • I couldn't get Django-nonrel to work despite following a variety of documentation sources to the letter. It's 'mostly' there, in that I have a Django project, and I can almost even get syncdb to work, but the best I've gotten is for it to start before it fails to ... crap, some error dealing with ObjectID. In short, I ended up using mongoengine, which allows me to specify a connection in settings as well as define "Django-like" class objects that I can refer to. Your answer didn't 'work', but since you took the time out to at least try, I figure that's worth something, so it's accepted. – bmelton May 05 '12 at 15:00
0

Adding onto dragonx answer. The issue with django-nonrel is that the auth module doesn't work.

You can perform many-to-mamy joins using $lookup operator. djongo does automatically for you. It translates SQL syntax into mongodb aggregation queries and populates the object model, like other SQL drivers.

The auth module works fine on djongo

nesdis
  • 1,182
  • 13
  • 16