7

I am not that experienced with django yet, but we are creating a project soon and we were wondering which database to use for our backend (Mongodb or PostgreSQL).

I've read a lot of post saying the differences between each, but I still can't take the decision of which to go for. Taking in consideration I never worked with Mongodb before.

So what shall I go for ??

Thanks a lot in advance

1 Answer 1

14

MongoDB is non-relational, and as such you cannot do things like joins, etc. For this reason, many of the django.contrib apps, and other 3rd-part apps are likely to not work with mongodb.

But mongodb might be very useful if you need to store schemaless complex objects that won't go straight into postgresql (of course you could json-serialize and put in a text field, but using mongodb instead is just way better, allows you doing searches, ..).

So, the best suggestion is to use two databases:

  • PostgreSQL for the standard applications, such as django core, authentication, ...
  • MongoDB only for your application, when you have to store non-relational, complex objects

You also might want to use the raw_* methods that skip lots of (mostly unnecessary) validation by the django orm.

Just remember that databases, especially sql vs no-sql, are not drop-in replacements of each other, but instead they have their own features, pros and cons, so you have to find out which one suits best your needs in each case, not just pick one and use it for everything.

UPDATE

I forgot to say: remember that you have to use the django-nonrel fork in order to make django support non-relational databases. It is currently a fork of django 1.3, but a 1.4-based version is work-in-progress.

Sign up to request clarification or add additional context in comments.

3 Comments

+1'ed. Can you provide a link to some resource about the raw_* methods? Thanks.
@JosvicZammit here it is the official documentation: django-mongodb.org/reference/lowerlevel.html
@redShadow I was thinking of using mongoengine, if I use Mongodb.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.