Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb vs PostgreSQL in django

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

like image 956
Salma Hamed Avatar asked Aug 11 '12 09:08

Salma Hamed


1 Answers

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.

like image 101
redShadow Avatar answered Sep 19 '22 09:09

redShadow