Adding and Querying to MongoDB from Django - django

I am trying to build a DB system using Django as the framework and MongoDB for my database management system. How can I add things to a specific collection? Where should I specify the name of the collection?
Then, after I have added to the collection, how can I use a Django shell to ask for that information from Mongo?

You don't "add a collection" on MongoDB -- you just use them. In Django - MongoDB: (could not connect to localhost:27017) Connection refused you already got Django MongoDB Engine running, so I don't understand your question? You can use the Django ORM to get data into and out of MongoDB now.

There are many good tutorials of using mongodb with Django. One popular way is to use django-mongodb which integrates to django models. Here is their tutorial.
Another screencast: Integrating mongoDB and Django.

Related

Using mysql and mongodb together for Django

Can I use both relational-database(eg : mysql) and non-relational database(eg : mongodb) together as bacekend dbs for a Django project? If possible then how?
I use Django version 1.11
Yes, kind of. MongoDB is not supported as a backend for Django's ORM, however, you can use through MongoDB Python.
What I would do, in this case, is use MySQL as your default database in your DATABASES setting. I would use MySQL for all of my Django ORM functions, and only use MongoDB where I need it. You can then connect to MongoDB for non-ORM connections via Python. See here for connecting to MongoDB via Python: https://api.mongodb.com/python/3.4.0/
There used to be a Mongo backend - again, without much ORM support - but last I saw, it hasn't been updated in several years: https://github.com/django-nonrel
Good luck!

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

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.

Django Authentication Mongodb

Hi everyone
I want to use django's built in authentication with mongodb. I have looked online and they aren't really any stable and solid solutions.
Has anyone mongodb fans out there who can point out to me how this can be achieved with minimal hacking? That would be great.
You can't simply use Django built in authentication with MongoDB because MongoDB is not supported as a back-end for django.db which is an ORM for Django Authentication. However you may use 3rd modules like MongoEngine or MongoKit to overcome this problem as they all provide Authentication Module for MongoDB Django apps.
Note: The folks at MongoEngine provide an awesome open source project named Mumblr which is good to use as a starter for your Django-MongoDB project.