Django 1.8 and MongoDB? - django

This question is already asked on StackOverflow,
The asked questions date back to 2013, Its 2015 now and Django has grown up fast.
What is the situation of using mongodb with Django 1.8 as of 2015?
Does Django support Monogodb out of the box (with db adapters)? or another distribution like django-nonrel should be used?

I don't think Django provides out of the box support for MongoDB. It is more tailored for relational databases.
One solution could be using MongoEngine.
MongoEngine is an Object-Document Mapper, written in Python for
working with MongoDB.
You need to just configure MongoEngine with Django and then it should work comfortably.

just my thoughts and somewhat subjective and opinionated but I would say it does not work very well. I quickly disbanded the idea of trying to run Django with MongoDB, since it's auth system is heavily reliant upon a relational database to work.
There are apparently ways around this, but ultimately I decided for my project it was not worth the effort just to use MongoDB.

Does Django support Monogodb out of the box (with db adapters)?
No, it does not. If you can find a django compatible engine for mongodb, then it will work perfectly.
The good news is there is such an engine, called django-mongodb-engine; the bad news is that it relies on django-nonrel which is not updated against the latest stable version of django.
So, if you must - you can use MongoDB at the expense of not having some updated django features available to you (and more importantly, any security patches).
If you want to supplement your main database with mongodb - that is, mongodb will not be your primary database, then the process is a lot easier.
So, in summary:
django 1.8 provides no out-of-the-box support for mongodb (or other non-relational databases) as the primary data store.
support is available using the third party django-nonrel package, which is behind the current django production version.

I came across a new package that does support the latest django on MongoDB: djongo
As stated above, mongoengine does not support all contrib apps of django. Especially the auth app doesn' work on mongoengine
Djongo claims to compile SQL queries into mongodb queries. So its is essentially version agnostic and works for all versions of Django.
Disclosure: I have contributed to this package by making minor bug fixes.

I know that its been three years but for those who are wondering about MongoDB and Django now should know that the situation has not changed. Mongoengine as described earlier is a good enough tool but still there are limitations. For instance when i integrated mongodb with django using mongoengine i was not able the use elastic search with my application. Furthermore with mongoDB you loose you loose Django admin and authentications functionalities. So, MongoDB with Django is still a risky choice

Related

How to use Postgres & MongoDB simultaneously in Django?

I am looking for a solution to work with Postgres and MongoDB simultaneously in my Django project.
I have large data which I would like to store in MongoDB and Postgres for user management, billing, and other things to manage.
I have tried to use a library ```pip install djongo`` djongo, which is outdated, and not able to find any solution. Please guide me with an authentic solution! Thanks
First of all, To install a newer version of Django you can use pip install Django==<version>, But you need to see compatibility with the Python version you're running on your system and virtual environment.
e.g. For Python 3.x, I'm using a bit older Django version 2.2.21.
Second, Django does not support MongoDB natively, But MongoDB team themselves provides a library called pymongo which you can install, but with pymongo you'll have to write more of a native mongodb queries. They do not have any Django ORM.
But there's another library called mongoengine which is actually built on top of pymongo and is very handy and close to the ORM Django provides for relational databases.
Thirdly, About Postgres you can easily set up any relational database with Django as it provides native support for relational databases. Both the database are completely independent of each other, So there should not be any problem with the setup.
I, myself use Postgres and MongoDB together in my projects, Never faced a single problem. Although, sometimes it's a little challenging to build things for NoSQL databases in Django which Django already provides for relational databases but yeah a little extra code as overriding Django base classes to provide support for mongodb always works.

django - how can I write data to an external Mongo database?

I have a Django app that is using PostgreSQL. Everything is fine. However, I have a situation in which it would be very convenient for my Django app to update the Mongo database of an entirely different app that is running a different server, etc. How can I do this?
I dont know what Django is or how you are talking to Postgress, but ultimately, it boils down to using one of the MongoDB supported language drivers in order to communicate with MongoDB. The programming languages supported are here: drivers
One option to consider is MongoEngine, an Object-Document Mapper (ODM) that implements a declarative API similar to Django. You can then use Django's support for multiple databases to route requests appropriately.
See:
Django Support in MongoEngine
Django documentation: Multiple databases

configuring mongoDB with Django

For few days I have been searching for a tutorial that shows how MongoDB can be used as a database with Django but resulted in nothing fruitful or clear tutorial. There have been questions regarding this in this forum most of them directed to look up for http://www.django-mongodb.org/ but I find there's something else written. Can anybody suggest me some good tutorial or pointers where I can start with.
P.S. I myself have searched a lot but couldn't find anything that tells the whole procedure.
The main options tu use MongoDB with Django are:
MongoEngine is an ORM for MongoDB with some Django Integration. This will not replace the Django ORM, but you're free not to use it.
Django MongoDB Engine provides a tighter intgration in Django by providing a MongoDB backend to the Django ORM, but requires the use of Django-nonrel, a fork of Django that adds support for non-relational databases.
The Django MongoDB Engine documentation formerly known as http://www.django-mongodb.org/ is now available at https://django-mongodb-engine.readthedocs.org/. For future reference, you can get the previous version of the site using the Internet Archive's Wayback Machine.

Is porting a Django app to GAE still an option?

I have started a month ago with GAE and have successfully deployed our current startup via Flask on GAE. It works fantastically well. Now being all too exited about GAE, I am thinking about porting a couple of my older Django apps on GAE as well.
To my surprise the documentation of it is surprisingly inconsistent and partially contradicting.
The official google page recommends using django-nonrel, which itself is already disconstinued.
Django 1.5.1 seems not even to be supported yet on GAE, neither is it clear to me how to use Django 1.4.3 on GAE.
I also found this more recent solution that utilizes Django and Google Cloud (Mysql on cloud) instead of the high replication datastore. Not sure if this is a good way to go since its still experimental and subject to "breaking changes" in future. (It also doesn't seem to include any free tier, unlike high replication datastore)
I was expecting Django - as perhaps the biggest python web frameworks - to have a far better documentation or tutorials about how to do deploy it on GAE. So I wonder if its even worth it sticking with Django on GAE anymore.
If I am meant to make manually my own models and adjust my queries in Views by utilizing ndb anyway, I could as well stick with flask+Jinja2, why should I use Django, where I can't even use it's ORM anymore? Or am I overlooking something?
Thanks,
There's nothing on the link to the allbuttonspressed blog that implies it is discontinued. On the contrary, the page says that even though they (as the original maintainers) are pulling out of the project, it has been taken over by a new maintainer. That's what often happens in open-source projects.
As for Cloud SQL, there is a dedicated page on the App Engine documentation which explains in detail how to get this up and running. The Cloud SQL API itself is, it's true, still in "experimental" status, but again that's just what Google does. App Engine itself only came out of "experimental" last year.
As for why you should stick with Django, that's up to you of course, but both of the above solutions will give you Django forms, the admin interface, templates, and URL routing, and some or all of the ORM syntax.
There's some work going on in maintaining django-nonrel, though the Allbuttonspressed blog is starting to get pretty out of date. You'll find more up-to-date info in the django-nonrel mailing list on Google Groups.
I believe it's been updated to at least Django 1.5, but I'm personally still running on 1.4. The documentation is extremely lacking. You'll have to figure out from the mailing list the appropriate branch to use to get support for the latest django version. However, it's there and it's working.
Django + CloudSQL will likely be the least-coding route to port your app to GAE.
Django-nonrel gets to take advantage of the HRD, however, many apps written expecting SQL behavior will need to be extensively rewritten to support the HRD behavior properly.
As an example, I've tried running django-registration on django-nonrel. On first look, it seems to work fine. But on deeper inspection, there's issues like being able to register the same email address to more than one user on HRD. You may find similar issues with other apps, or just the inability to run at all, given that the HRD doesn't support many-to-many relations, as well as slightly-more-complex queries.

Do we still need django-nonrel now that GAE (allegedly) supports Django out of the box?

According to this question:
Django on Google App Engine
The easiest way to get started with GAE/Django is with the Django non-rel bundle. However now that the latest Python/GAE SDK includes a build of Django, do we still need this?
What's the best-practice for getting started wth Django on GAE right now?
Thanks
Update: It seems that Web app2 is the easiest choice for new projects.
This guest article suggests that
"App Engine does come with some Django support, but this is mainly
only the templating and views."
non-rel is still seemingly your best bet. Although I'd caution you that further development and/or maintenance may not happen according to their blog.
Normal Django's models doesn't have a backend supporting GAE's datastore. Hence you can't use Django models, and hence, Django's model forms. What you'd have to do use use models derived from GAE's python db.Model(). Instead of using Django's ModelForm class for forms, you would use google.appengine.ext.db.djangoforms. Note, that's specifically for ModelForms, other forms work fine since they're not tied to the database.
I can think of two good reasons to use Django-nonrel:
1a) you have a existing project on Django. Using Django-nonrel would be the laziest way to go. Rewriting models to GAE's models isn't too hard, but it could be a small pain, especially if
1b) you use a lot of existing Django components, and you'd have to go through all of them to update the models and forms.
2) You want to hedge your bets against GAE. Using Django-nonrel will allow you to switch over to MongoDB with very little effort, since Django-nonrel has a functioning MongoDB backend. The current Django-nonrel maintainers seem to be more interested in MongoDB.
Having worked with Django-nonrel, I've so far run into some reasons why it may be a bad choice:
1) No support for ancestor queries. There's an outstanding pull request for this though. It won't be compatible with any other DB backend though.
2) ndb is coming out, and seems like it'll have a few more benefits, that likely won't see support on Django-nonrel.
If you do use GAE's native db API, the main benefit from Django would be the form validation. Otherwise, webapp2+jinja2+gae db.Models() would provide similar functionality to Django.