Hacker News new | ask | show | jobs
by acabajoe 4133 days ago
Is there a guide somewhere for someone that has used mongodb before but is new to postgres on how to map the first to the second? Would love to try some of this out, but the complexity is a little daunting.
2 comments

The SQL can look a bit complex at first, and advanced queries can look complex, but MongoDB is quite limited what operations you can do with it, so the SQL queries that correspond to MongoDB operations are fairly simple.

Here's a documentation from MongoDB which could be used the other way as well: http://docs.mongodb.org/manual/reference/sql-comparison/

For normal use you really need 4 operations:

SELECT - query data

INSERT - inserting data

UPDATE - modifying existing data

DELETE - remove data

Everything else is either used for database maintenance or DDL (Data Definition Language, defining how the data is stored) commands.

The DDL is the main reason why some organization are considering using MongoDB, they believe that by removing the schema (definition how data is stored) they will get more flexibility, the problem with it is that if you use MongoDB you still will have schema, the issue is that the schema will be enforced by your application. And if you don't enforce the structure you'll end up with quite a mess, and very complex code.

Also if you use Java (or JVM based language) there are many frameworks that supposed to help interacting with database each has their strengths and weaknesses. There's one called JOOQ[1] that allows you to write SQL queries in Java in a way very similar to MongoDB.

Edit: There's also article about MongoDB aggregate functions and equivalent PostgreSQL: http://tapoueh.org/blog/2014/02/17-aggregating-nba-data-Post...

[1] http://www.jooq.org/

I was in this exact situation two weeks ago. Because Mongo databases tend to have an implicit schema, I used variety.js (https://github.com/variety/variety) to first uncover it for a given collection. I then hand-created a SQL table that corresponds to said collection, using variety.js's output as a guide for what types to use.