How Can I Use Django 3 with MongoDB? - django

Is there a way that I can use Django 3 + MongoDB because djongo (the package which integrates MongoDB and Django) requires Django 2.x. Note that I don't want to move to Django 3 for specific reasons. I just wanna explore it. and I need MongoDB because I am writing a data analysis web app (since NoSQL Databases Perform well when working with large data sets). thanks in advance.

you can use Mongoengine and you don't need to run migration commands but Mongoengine do not support regular Django contrib libraries directly, so it would be more complicated to adjust it to Django regular libraries which means it’s hard to have admin and other Django regular libraries

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 1.8 and MongoDB?

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

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

How to migrate Django project to Google App Engine

I am looking for a guide to migrate Django project to Google App Engine and use Google's datastore. The most of the guides I found were linked to Django-Appengine using Django-nonrel (but I want to use GAE's native support).
Going through GAE getting started guide, it says:
Google App Engine supports any framework written in pure Python that speaks CGI (and any WSGI-compliant framework using a CGI adaptor), including Django, CherryPy, Pylons, web.py, and web2py. You can bundle a framework of your choosing with your application code by copying its code into your application directory.
I understand that I won't be able to use some features of Django in that case (majorly the admin feature) and would also need to restructure the models.
From other reading, I also found that latest SDK of GAE now includes Django 1.3 on Python 2.5.
I tried to put all files from my Django application to a GAE project, but couldn't get it all to work together.
Please provide some basic guide using which I may migrate my Django project to Google App Engine's code.
Thanks.
For an existing Django app, using django-nonrel is the simplest approach; it is very popular so you should be able to find help with specific errors you get quickly.
Another approach is written up in this article: http://code.google.com/appengine/articles/pure_django.html -- it goes the other way, taking an App Engine app that uses Django for dispatch, templates, and forms, but not for models, and describes how to make it run in a native Django environment. Maybe you can glean some useful hints for your situation from it.
I've used django-nonrel, which behaves pretty much like django, except that operations with JOINs will return errors. I've basically worked around this by avoiding ManyToMany fields, and essentially building that functionality manually with an intermediate table.
So far I've ran into two problems with Django-nonrel:
1. No access to ancestor queries, which can be run in a transaction. There's a pending pull request for this feature though.
2. You can't specify fields that are not indexed. This could significantly increase your write costs. I have an idea to fix this, but I haven't done so yet.
(Edit: You CAN specify fields that are not indexed, and I've verified this works well).
2 (new). Google is pushing a new database backend called ndb that does automatic caching and batching, which will not be available with django-nonrel.
If you decide not to use django-nonrel, the main differences are that Django models do not run under App Engine. You'll have to rewrite your models to inherit from App Engine's db.Model. Your forms that use Django's ModelForm will need to inherit from google.appengine.ext.db.djangoforms instead. Once you're on App Engine, you'd have to port back Django if you ever take your app somewher else.
If you already have a Django application you might want to check this out. You won't work with App Engine's datastore but Google Cloud SQL might fit your needs.

Django on GAE: use_library vs Django-nonrel

I am really new to the world of App Engine development and I want to start with a test project on Django and GAE. I've done some research and found out that there are two major ways to use Django in my app on GAE.
Django-nonrel + djangoappengine
use_library() to load Django from SDK
Please tell about pros and cons of each way.
Is there anything better than django-nonrel if i will decide to distribute Django code with my project?
It's not a matter of two different ways to use Django - it's two different versions of Django. App Engine comes bundled with versions 0.96, 1.0 and 1.1 of Django, unmodified from the mainline release. Django-nonrel is a branch of Django, which adds support for App Engine for the database backend.
If you're writing a new app, and you want to use Django for the whole app, including the models, you should use Django-nonrel.
When using django-nonrel you can use all Django features (including admin, auth, models, queries). I don't have a complete list of django modules which are either not working or partly not working in app engine.
If you use the Django version via use_library you have to be careful with app engine's limitations (use their model api, their auth via google accounts and so on).