Mongodb and Postgresql Thoughts

MongoDB and PostgreSQL thoughts

You dumped a decades-tested, fully featured RDBMS for a young, beta-quality, feature-thin document store with little community support. Unless you're already running tens of thousands of dollars a month in servers and think MongoDB was a better fit for the nature of your data, you probably wasted a lot of time for negative benefit. MongoDB is fun to toy with, and I've built a few apps using it myself for that reason, but it's almost never a better choice than Postgres/MySQL/SQL Server/etc. for production applications.

Using PostgreSQL or PostgreSQL + MongoDB?

tldr: Use PostgreSQL.

Long answer:

You are trying to pre-optimize for a problem you don't even know if you will have. You don't know how many geolocations you will have, what the usage behaviors will be of your users and you probably don't even have any users yet.

I've used MongoDB before and migrated to PostgreSQL. There are many, many features and benefits to using a 'real' database for storing highly structured data. I suggest googling around for 'PostgreSQL vs X' articles, but the overall consensus that I've found is that PGSQL is extremely mature, reliable, performant and supported.

From my personal experience using Mongo then switching to PGSQL, I will never use Mongo again unless PGSQL (or another full-fledged SQL database) is completely falling over and I've spent months fixing it. Even then I'd take a hard look at other NoSQL databases too. PGSQL has so many amazing features and powerful tools that make it a joy to use.

For the seemingly few things you think you need Mongo for, PGSQL can do, and do just as well or better. It has native JSON types with indexes, geo support, full text indexing, etc. PGSQL has been around longer and has more support (useful for debugging, performance tuning, etc).

Regardless of which technologies you are thinking of using, you can't make any sort of informed decision if you don't:

  1. Test with large data sets

and


  1. Know your usage patterns and data volumes

So at this point I'd pick the more matured and powerful tool and setup monitoring for it. Watch the usage and performance of PGSQL, see how it holds up. Research best practices for PGSQL. Get to know it, learn it, dive in deep. When it comes to scaling individual services, each one is somewhat unique and will not fit a simple "Should I use X or Y?" question.

Good luck!

How to choose between MongoDB and PostgreSQL for GIS?

PostgreSQL can give you full (geo)spatial functionalities via PostGis, although you may not need that much in your application.

If you need just to quickly find users within a certain radius of a (lat, lng) point, you can use the earthdistance module, together with GIST indexes.

Check How can I speed-up my query on geo-location processes for detailed explanations.

Check also Searching in a Radius using Postgres.


In MongoDB, you would use geoNear functionality and 2dsphere Indexes


Querys in PostgreSQL are very fast and very flexible, and they scale very well. You need a little bit more of work to set it up than you would with MongoDB.

Anyhow, the basic functionality is available in both, and you should decide considering all other factors:

  • Is your data well structured, and with few variations within this structure? (more on SQL side)
  • Do you need ACID (atomicity, consistency, isolation, durability) guarantees? (more on SQL side)
  • Do you need huge horizontal scaling? (more on MongoDB side)
  • Do you need to query several tables at once (and join)? (SQL side)
  • Do you feel more comfortable with JavaScript and JSON than in any other languages? (MongoDB +)
  • (etc., etc.)

Check also Postgres Outperforms MongoDB and Ushers in New Developer Reality and System Properties Comparison MongoDB vs. PostgreSQL, among many others.

Mongodb vs PostgreSQL in django

MongoDB is non-relational, and as such you cannot do things like joins, etc.
For this reason, many of the django.contrib apps, and other 3rd-part apps are likely to not work with mongodb.

But mongodb might be very useful if you need to store schemaless complex objects that won't go straight into postgresql (of course you could json-serialize and put in a text field, but using mongodb instead is just way better, allows you doing searches, ..).

So, the best suggestion is to use two databases:

  • PostgreSQL for the standard applications, such as django core, authentication, ...
  • MongoDB only for your application, when you have to store non-relational, complex objects

You also might want to use the raw_* methods that skip lots of (mostly unnecessary) validation by the django orm.

Just remember that databases, especially sql vs no-sql, are not drop-in replacements of each other, but instead they have their own features, pros and cons, so you have to find out which one suits best your needs in each case, not just pick one and use it for everything.

UPDATE

I forgot to say: remember that you have to use the django-nonrel fork in order to make django support non-relational databases. It is currently a fork of django 1.3, but a 1.4-based version is work-in-progress.

MongoDB + Postgres (or do I need a graph db?)

After spending the last several hours researching further, it does appear that a graph database is the right solution to managing the "association" feature that I'm looking to develop here because the actual relationships will be rather multidimensional in nature.

Furthermore, I've decided to go with ArangoDB as it merges key-value (ie. Redis or postgres' hstore IIRC), document store (ie. Mongo's documents or Postgres' JSONB), and also does graph database functionality. Arango can do joins between documents and, even better, it has a single, unified query language that works across all 3 types of models. It also has a rather robust tooling environment around it already that seems pretty promsing.

I found this youtube video rather enlightening as well if anyone wants a nice introduction to understanding why you might want to use a "multi-model database" like ArangoDB.

MongoDB Or PostGreSQL which will be better With Python Django and Express and Node js

A SQL RDBMS is definitely your choice. If you are selecting between Mongo and PostgreSQL then PostgreSQL will be the answer.

As it's stated in Mongo official FAQ:

MongoDB may not be a good fit for some applications. For example,
applications that require complex transactions (e.g., a double-entry bookkeeping system) and scan-oriented applications
that access large subsets of the data most of the time may not be a
good fit for MongoDB. MongoDB is not a drop-in replacement for legacy
applications built around the relational data model and SQL.

Is it a good idea to use mongodb , inmemory db and postgres together?

No. The simplest design is the best design, unless your requirements dictate something more complex is needed. PostgreSQL alone is mature and proven, and can be tuned to cache data in memory as well. I recommend building directly on PostgreSQL until you find that performance is not sufficient. I use PostgreSQL as our sole database technology for a busy national website and it works great.

At least choose one database to start with instead of three.

How come many startups used MySQL or PostgreSQL rather than MongoDB when they began?

To quote User Dan Grossman:

You dumped a decades-tested, fully featured RDBMS for a young, beta-quality, feature-thin document store with little community support. Unless you're already running tens of thousands of dollars a month in servers and think MongoDB was a better fit for the nature of your data, you probably wasted a lot of time for negative benefit. MongoDB is fun to toy with, and I've built a few apps using it myself for that reason, but it's almost never a better choice than Postgres/MySQL/SQL Server/etc. for production applications.

Mongodb and PostgreSql thoughts

Mongodb vs Postgres in Nodejs

Choosing between an SQL database and a NoSQL database is certainly being debated heavily right now and there are plenty of good articles on the subject. I'll list a couple at the end. I have no problem recommending SQL over NOSQL for your particular needs.

NoSQL has a niche group of use cases where data is stored in large tightly coupled packages called documents rather than in a relational model. In a nutshell, data that is tightly coupled to a single entity (like all the text documents used by a single user) is better stored in a NoSQL document model. Data that behaves like excel spreadsheets and fits nicely in rows and is subject to aggregate calculations is better stored in a SQL database of which postgresql is only one of several good choices.

A third option that you might consider is redis (http://redis.io/) which is a simple key value data store that is extremely fast when querying like SQL but not as rigidly typed.

The example you cite seems to be a straightforward row/column type problem. You will find the SQL syntax is much less arcane than the query syntax for MongoDB. Node has many things to recommend it and the toolset has matured significantly in the past year. I would recommend using the monogoose npm package as it reduces the amount of boilerplate code that is required with native mongodb and I have not noticed any performance degradation.

http://slashdot.org/topic/bi/sql-vs-nosql-which-is-better/

http://www.infoivy.com/2013/07/nosql-database-comparison-chart-only.html



Related Topics



Leave a reply



Submit