user2495766
user2495766

Reputation: 123

django 1.5 with mongodb

I would like to work with the django(currently 1.5.2) with the mongodb (currently 2.4.6). Till now I had tried:

  1. mongodbengine: didn't like inherit from a Document class (he said it better).
  2. django-mongodb-engine which was exactly what I wanted only when it runs my django jumps to 1.3 instead of the 1.5.2 [I didn't give it much thought, guessed its the norel from the 1.3 branch and assuming it would be best to stay at 1.5.2].
  3. looke at those and trying to save myself some time asking here..

Please advise, my goal is to run django 1.5.2 (with virtualenv) so I could use normal models with mongodb DB. What is the best approach?

Upvotes: 2

Views: 845

Answers (2)

stormlifter
stormlifter

Reputation: 3841

You could use a SQL relational database for the django models like User. Then you can use a Database Router to route based on the app name, if it's auth then use the relational database. This will let you specify by app/model which database to use.

An example from someone on this site: Mixing Postgres and Mongo.

Upvotes: 1

Nafiul Islam
Nafiul Islam

Reputation: 82560

I'm afraid that django and mongoengine do not have an integration yet, but its still in the works. If you want to use mongoengine, I would suggest that you use flask, because the other way you have to use it is rather frustrating, wherein you need to connect to mongodb using a cursor, in your models.py file and then inheriting from Document to make your classes.

Thus, every single time you need to use your models, you will need to connect back, hitting your database several times over. This is not how django usually operates, since it uses one connection to handle multiple queries to make things more efficient.

This becomes a REAL pain in the long run, and I would strong discourage you using django and mongoengine or mongodb for that matter, and especially for a person who is brand new to django in the first place.

If you're new to django, then please use a RDBMS like Sqlite3 or PostgreSQL to do your development. But if the use of mongodb is a must, then I suggest that you reconsider using django in the first place, because mongodb has a better integration with flask, through mongoengine.

And I would suggest that you do not use anything other than mongoengine when dealing with mongodb, because mongoengine has the best support for mongodb, and is by far the most flexible option out there when working with mongodb and python. Not only that, but the syntax is almost identical to that of django's ORM.

I deeply regret I cannot provide a better answer, the only solutions remains making a connection every single time, and not to mention that all of this does not integrate well with django's forms, which is a big bummer.

Upvotes: 3

Related Questions