official support of MongoDB in django - python

I want to use the MongoDB database in Django.
Officially there are no Django-MongoDB drivers available. I found some third-party sources, but they're outdated. I found some projects on GitHub, but they are also outdated (last updated 2-3 year ago).
What are my option? Is there any official support for MongoDB in Django?

This tutorial looks like best solution at this point.
You need to install django#nonrel and djangotoolbox so non-relational db can work properly on your django project.
After installing mongodb-engine just activate it in settings.py file

Related

Django with NoSQL database

I am working with an Django application which uses Django 1.8 version.
Most of the data we deal with is JSON formatted ones. We are trying to implement any NoSQL database.
But I see that MONGODB is not compatible for version 1.8 and over and Is there any NoSQL database that can be efficiently mapped to Django 1.8 or over ??
Thanks in advance.
NoSQL databases are not officially supported by Django itself. There are, however, a number of side project and forks which allow NoSQL functionality in Django, like Django non-rel.
You can also take a look on the wiki page which discusses some alternatives.
This is quoted from the django official documentation
Here is an interesting repo for allowing using MongoDB as your django backend. It works by compiling SQL commands into MongoDB document queries.
Most of the basic stuff like django admin, django session etc all work.
https://github.com/nesdis/djongo
Years after (2022), djongo is still the only option which works fine with Django 3.0.x as well (with some constraint restrictions) in NoSQL environment.
But now that Django's 4.0.1 major release is in the air, djongo's latest 1.3.6 (released in June 2021 according to pypi) is beginning to break. In my experience with Django==4.0.4 and djongo==1.3.6 together, almost none of the select/update queries work, and SQLDecodeError exceptions lay around in console.
djongo maintainer(s) have created paid subscription plans as well, but I have not been their customer like that so can't comment anything about the commercialized version of djongo. Rest, the open-sourced AGPL licensed djongo is the only best option for unpaying developers to use Django with MongoDB, given that the developer restricts themselves to Django 3.0.x.
I've been using Django==3.0.5 with djongo==1.3.6, to be specific here, which works fine in most of the circumstances.

Django MSSQL Database Backend vs. Django PYODBC

I'm new at both Python and Django and still trying to figure out the best environment for my development. As far as I saw, there are 2 options available for establishing a connection to a MSSQL database which are:
Django MSSQL Database Backend: http://django-mssql.readthedocs.org/en/latest/
Django PYODBC: https://github.com/lionheart/django-pyodbc/
What I want to ask is the difference between those 2 options and their pros/cons over each other. Do they differ from each other especially in terms of performance and stability?
(I have only found the link below in stackoverflow but it was quite limited and outdated so I've wanted to ask another question. Sorry if there are any recent ones that I haven't seen yet.)
django-pyodbc vs django-mssql
Thank you.
I chose django-mssql when I started my project two years ago, as it is optimized specially for SQL Server whereas django-pyodbc relies on pyodbc which is a generic ODBC driver.
Of course there are some bugs, but the package is actively maintained. So far it does the job very well for me.
The main downsides :
Only runs on Windows (depends on pywin32 package)
Django version support far behind latest (current stable version supports Django 1.7, and development version is for Django 1.8...)
Migrations are a little buggy. You may have to alter generated sql by yourself in some cases.
django-pyodbc seems to support latest Django version and is cross-platform, however I have not found any positive opinion of people that use it in production back when I had to choose between the two.

Upgrade Django from 1.6.2 to latest version (~1.8)

So I've been tasked with upgrading a Django server from 1.6.2 to the latest (~1.8), along with upgrading Python from 2.7.3 to 3.3. I suspect this is going to break quite a bit of code. (I even need to upgrade the Ubuntu installation from 12.04 to 14.04)
I would like to migrate my Django app from the server it's currently running on (Ubuntu 12.04) to a virtual machine, and use that environment as a sandbox to make changes.
Would anyone be so kind to provide guidance on django app migration? Please let me know if you'd like me to provide any specific details.
Thank you.
Edit: If anyone would like to vote down this question because they believe I haven't done enough research, I'm very happy to add missing information, if I know what you're looking for.
Django versions from 1.5 onwards has been designed so that the same code will work on both versions of Python as in the documentation thanks to them following the six compatibility layer.
You might face some issues with code that isn't strictly related to Django components like print statements and other such parts that might have been coded in. The official Python Porting Guide should held you with that.
Django 1.8 is a LTS (Long Term Release) so it's a good idea to upgrade to it. Migrating the database might be a bit of an issue considering it's from 2.7 to 3.4 but that's in all likelihood the place you'll find most issue with. The How to Migrate is a great resource.
If I recall correctly the directory structure is a bit different in 1.6 so you'll have to move some code and files manually. I suggest having the tutorial pages for both versions 1.6 and 1.8 open and comparing the directory structure.
Going through the first 2 pages of the tutorial should give you enough of an overview to migrate the database and the settings file. This should also help with migrations.
The 3rd and 4th pages should get you through migrating the views and urls files.
The only thing I'm not familiar with is the migration of the wsgi file which has configuration information, you should be able to find some basic information about that here.
Updating your Ubuntu however won't change or affect anything at all.
Also as has been said in the comments by jape and joel, it's a good idea to use virtualenv and git.
I would like to add another suggestion based on my own experience with pushing code to a Django server :
Download the code base to your local machine and work there and once you're done and the server is working well on your machine push it all to the server at once. That way you can isolate server machine specific issues from coding issues.

How would I go about plugging mongoengine into pyramid?

I've created a basic mongoengine app using the pyramid_mongodb scaffold...however I'd like to include mongoengine. I'm wondering what I should actually keep from the scaffolds code.
Not a answer regarding the scaffold. I wouldn't recommend using the scaffold since it's not really usable for root_factory and so on, the subscribers isn't really needed too.
I wrote an addon for pyramid. It's called pyramid_mongo.
Documentation:
http://packages.python.org/pyramid_mongo/
Github:
https://github.com/llacroix/pyramid_mongo
I saw your question today and felt it could be a good addon to the plugin.
I just pushed it to github so you need to clone it from there for now, installing using pip will load the old version without support for mongoengine.
In other words in your config, do everything like in the docs and add something like:
mongo.mongoengine=true
It will attach mongo from the config to mongoengine. All other api will work with or without mongoengine and mongoengine should work. It just added it today, it doesn't support multiple connections and multiple dbs. I can also add support for multiple dbs too. But I feel mongoengine may do some things on his own that could conflict with my plugin like authorization.
Once I write tests, I'll push it to python packages and it will be possible to install from pip or easy_install. For now, pull it from github

Python Web Framework with best Mongo support

I'm looking to write a small web app to utilise a dataset I already have stored in a MongoDB collection. I've been writing more Python than other languages lately and would like to broaden my repertoire and write a Python web app.
It seems however that most if not all of the current popular Python web development frameworks favour MySQL and others with no mention given to MongoDB.
I am aware that there are more than likely plugins written to allow Mongo be used with existing frameworks but so far have found little as to documentation that compares and contrasts them.
I was wondering what in people's experience is the Python web development framework with the best MongoDB support?
Many thanks in advance,
Patrick
I have not tried MongoKit although it has been around for a while and retains a good reputation. I personally prefer MongoEngine and feel very comfortable with it (maybe because I like its nice homepage and good documentation). There is also a very good opensource project named Mumblr which demonstrates a Django-MongoEngine-MongoDB combination, which I think a very good starter for any project. I'm developing a CMS for my own company using this app.
I've used MongoKit with Pylons before and it worked out good.
You might want to refer to this post though: MongoDB ORM for Python?
There is no stable support for mongodb using django framework. I tried using mongoengine, but unlike models, provided for admin in django framework, there is no support for mongoengine.
Correct if I am wrong.
Flask is the best framework to use with MongoDB. It has a mongodb library called flask-pymongo
Make sure you run the following commands before starting your project.
$ pip3 install Flask
$ pip3 install Flask-PyMongo

Categories