4
votes

I'm new to Django and Mongodb seems really cool and I have a few questions ! I'm using Django nonrel with Django Mongodb Engine. I hope I'll not make too many mistakes :)

1 ) Are the Django user authentication system and the Django Session system working fine ? Because I see on allbuttonspressed.com that there is a problem with authentication and admin interface and the part with the 3rd party written authentication backend makes me think that the django authentication system doesn't work with mongodb :

You can only edit users in the admin interface if you add "djangotoolbox" to your INSTALLED_APPS. Otherwise you'll get an exception about an unsupported query which requires JOINs.

Florian Hahn has also written an authentication backend which provides permission support on non-relational backends. You should use that backend if you want to use Django's permission system.

2) If the authentication system works fine, how can I add fields to the user model ? I saw on the Django docs that to achieve that the way to go is to define a model with a OnetoOnefield to the user model ( "user = models.OneToOneField(User)" ) and define the other fields we want in that model. I get it that must be the right way with SQL databases. But with NoSQL like mongodb that just seem wrong to me, if I'm not mistaken it creates a new collection and puts in each document an user field used to link the document to the document in the User collection ( exactly like a foreign key ). That doesn't seem to be a NoSQL way at all ( Well It's just my feeling but since I'm just a beginner I may be wrong, don't hesitate to correct me ). Is there a recommended way to add fields directly to the User model ?

3) When the Model is used in Django, it puts all the fields in the document even if they are empty right ? Isn't that a waste of space to write down a lot of fields names in documents if they are empty ?

4) This question is more about Mongodb itself than the engine but I'll ask it anyway, you may have the answer : How much extra space does it take to index a field in a collection ?

Didn't think I would have written so much, I hope some of you had the courage to read me !

Thanks in advance,

Nolhian

1

1 Answers

1
votes

Only a partial answer as I don't use MongoDB.

  1. I'm using django-nonrel in a Google AppEngine project. I'm using those other custom apps like "djangotoolbox", and some backends for GAE. Admin panel and standard Django authentication are working very well. I suspect it's the same for MongoDB (like mentioned in the quotation you have provided)

  2. You're right. The standard approach is definitely good for relational databases, but might not work or work inefficiently for NoSQL databases. The typical scenario is to duplicate the data to another table, so you don't have to do JOINs. I think you can simply subclass the User model and add your fields to your custom model (docs).