I have a django REST application that uses Mongoengine. I want to integrate the application with elasticsearch. I understand that databases (like MySQL, Postgres etc.) can be integrated with elasticsearch using haystack but how to do it with MongoDB?
Saim, the fact you want to add elasticsearch to the stack means that you might want to index the data that is managed by mongoengine for full-text search and aggregation purposes. So you are looking for a library to index models (stored in mongo) and be accessible through the django API, I'd recommend this article ElasticSearch with Django the easy way where the author integrates the Django models to write into ES index via elasticsearch-py and read[search] directly using elasticsearch DSL via elasticsearch-dsl, you will realize this approach is database agnostic as well.
IMO, I have done some integrations Django<--->ES, the simpler ones, use directly the elasticsearch http api inside a Django model manager to nail the task.
Related
I am planning to develop a AI-Enabled Stock Market Project using Django & Tensorflow
For Clients, I plan to use MSSQL
For Stock Tickers, I plan to use MongoDB
How do I do it in Django?
I am in Planning stage
Django is good for using a single database. I strongly advise you to use an API. This allows you to connect to as many databases as you want. You can use Django Rest API if you want.
However you can find this documentation : docs.djangoproject.com/en/4.1/topics/db/multi-db
We have an existing Apache Ignite in-memory DB with lots of stored data. I want to connect my existing Django web application to the Ignite DB in order to query the existing data. Are there any examples of how to connect a Django application to an Apache Ignite DB and how to query the DB using the Django ORM?
You can use JDBC drivers with Django ORM: How to write custom database adapter for django using JDBC drivers?
Then, you can use Ignite JDBC driver: https://ignite.apache.org/docs/latest/SQL/JDBC/jdbc-driver
Django ORM requires a special adapter for each kind of database server. Such an adapter is called “database backend” in Django terminology. There is no Django database backend for Ignite. There is also no universal, middle-ground backend I know of, that can be used with Ignite.
You can implement your own custom backend (guidelines) or try to pick up the latest attempt in creating a more-or-less server-independent ODBC backend. But in your place I'd probably not get involved in any of this, since it implies a lot of work not directly related to your task.
I'd just convert the data with one-off script (or Django management command), using pyodbc or pyignite as a source and Django model as a target.
I am using Postgresql in Django and Python,and I do all the CRUD operation successfully but I don't know how can I call Postgresql procedure from Django and show the result in my web application!!
This should be completed using Django's ORM (Object Relational Mapper) querysets which is a Django wrapper that adds a layer of abstraction above an SQL query that retreives a given dataset from PostgreSQL (or another supported database).
Indeed, the existence of this layer is in place for security reasons in addition to enabling a developer to use any of the supported underlying databases (SQLite3, PostgreSQl, MySQL, Oracle or Maria DB (Django 3.0+)) by simply switching out the database credentials and settings.
The rendering of the datasets will be completed with either Django's templating system if you're usind Django across the entire stack. It could also be completed by creating APIs and using a front-end framework to render from them.
You should Google Django ORM and Datasets for further information, documentation and tutorials to achieve this.
I have a large mongo database with documents and i want to make Django website that is going to be a client to this mongo database but it can only filter (aggregate) and view information from database without any edit/update operations. I don't want to put other web site data (users' data, comments, other information) to mongo db.
I'm new to django framework and i wonder if it is better to connect mongodb and django using, for example, mongoengine and use two databases (one for the web site data, and the second one for external documents in mongodb) or use pymongo inside django to fetch data from external db and somehow transform it to djungo models?
Yup, you're spot on, in your case of needing two separate databases, it would be better to use mongoengine in order to use two separate databases. Check out this link. It goes over defining what database to use on a per-model basis so to say.
That most likely would work great. Basically you can query using the model the same way, regardless of the database is uses, but describe which database to use on the model itself.
Hope this helps!
This is what I have :-
Ubuntu 11.10.
Django 1.3
Python 2.7
What I want to do is build an app that is similar to top-coder and I have the skeletal version of the app sketched out. The basic requirements would be:-
1. Saving the code.
2. Saving the user name and ranks.(User-profile)
3. Should allow a teacher to create multiple choice questions too.( Similar to Google docs).
I have basic knowledge of Django and have built couple of (basic) apps before. Rather than building an online tool, is it possible to build something very similar to conf2py that sits on top of web2py, in Django.
Lets call this small project examPy( I know, very original), is it possible to build an app that acts more a plug-in to Django or is my concept of Django absolutely wrong?
The primary question being:
As I want to learn a new DB and have worked on postgres in Django, should I chose CouchDB or MongoDB for Django?
Answers can be explanations or links to certain documentations or blogs that can tell me the pros and cons.
General Differences
Comparing MongoDB and CouchDB
MongoDB VS CouchDB
Battle of the NoSQL Stars
Django Specific
MongoDB for Django-nonrel
Django-MongoDB Engine
MongoDB Hearts Django?
An Introduction to Using CouchDB with Django
Using CouchDB with Django
All my research points me towards the idea that Mongo and Couch are similar enough that your choice would probably boil down to personal (subjective) preference even over the use-case. Personally, I've developed a CouchDB fetish and am looking for a reason to use it.
The key factor influencing your decision should probably be which noSQL solution has the most mature ORM framework for Django?
I've used mongo-engine with Django but you need to create a file specifically for Mongo documents eg. Mongo_models.py. In that file you define your Mongo documents. You then create forms to match each Mongo document. Each form has a save method which inserts or updates whats stored in Mongo. Django forms are designed to plug into any data back end ( with a bit of craft ).
If you go this route you can dodge Django non-rel which is still not part of Django 1.4. In addition I believe django-nonrel is on hiatus right now.
I've used both CouchDB and Mongo extensively. CouchDB has a lovely interface. My colleague is working on something similar for Mongo. Mongo's map and reduce are far faster than CouchDB. Mongo is more responsive loading and retrieving data. The python libraries for Mongo are easier to get working with ( both pymongo and mongo-engine are excellent )
Be sure you read the Mongo production recommendations! Do not run one instance on the same node as Django or prepare to be savagely burned when traffic peaks. Mondo works great with Memcache/Redis where one can store reduced data for rapid lookups.
BEWARE: If you have very well defined and structured data that can be described in documents or models then don't use Mongo. Its not designed for that and something like PostGreSQL will work much better.
I use PostGreSQL for relational or well structured data because its good for that. Small memory footprint and good response.
I use Redis to cache or operate in memory queues/lists because its very good for that. great performance providing you have the memory to cope with it.
I use Mongo to store large JSON documents and to perform Map and reduce on them ( if needed ) because its very good for that. Be sure to use indexing on certain columns if you can to speed up lookups.
Don't use a circle to fill a square hole. It won't fill it.
I've used CouchDB with Django for a production application. Couch is fine and has some great ideas, but I'm moving that app over to MongoDB. Why? There is support for Mongo in the Django community. Django-nonrel has a MongoDB backend. Using Django-toolbox I can embed models in models and have some basic admin support.
If I remember correctly, Django-nonrel will eventually be rolled into Django core. In five years time I see much more support for Mongo in Django than Couch. Of course that can change, but I see Mongo a better fit.