4 ms·
Yes. We have applications running on both PostgreSQL and MongoDB and I find that working with MongoDB is just more pleasant. I think it mostly boils down to my
by jiripospisil 6y ago
Yes. We have applications running on both PostgreSQL and MongoDB and I find that working with MongoDB is just more pleasant. I think it mostly boils down to my preference of document databases as opposed to relational ones. It feels much more natural to me to embed / nest certain properties within a document instead of spreading it across several tables and then joining everything together to get the complete data. MongoDB makes working with these sometimes nested documents easy (I mean, it better) and there's always Aggregation Pipeline when you need it (something that I again find much more pleasant and readable over SQL).
What always irks me is when somebody suggests PostgreSQL's json (or jsonb) types as an alternative to using MongoDB. All it's saying is that the person hasn't really invested a lot of time into MongoDB because there are things that PostgreSQL simply cannot do over a json type, especially when it comes to data updates. Or it can do that but the query is just overly complicated and often includes sub queries just to get the indexes into the arrays you want to update. All of that is simple in MongoDB, not really a surprise - that's exactly what it was made for. The last time I worked with PostreSQL's json I sometimes ended up just pulling the value out of the column entirely, modified it in memory and set the it back to the db because that was either way easier or the only way to do the operation I wanted (needless to say there are only exceptional cases where you can do that safely).
Lastly, if you can easily replace MongoDB with PostgreSQL and its json types or you're missing joins a lot (MongoDB does have left join but it's rarely needed), chances are you haven't really designed your data in a "document" oriented way and there's no reason to use MongoDB in that case.
- heipei 6y agoYep, the update operators for MongoDB are really great and not replaceable with Postgres. Now if only MongoDB had a good sharding story it would be a worth contender for me.
- takeda 6y agoAs a person not familiar with mongo, what is it? From looking at the manual or looks like it's Mongo's equivalent of UPDATE statement.
- scarface74 6y agoAnd if you’re using C#, the MongoLinq library makes using Mongo with Linq just as easy as using EF with an RDMS. We were able to easily support both in a product just by passing Linq expressions to different repository classes and the expressions were translated to either Sql or MongoQuery by the appropriate provider.
- asah 6y agoI'm curious, any chance you remember some of those json/jsonb update hassles? (not arguing, just curious - when things get hairy in JSON, I give up on SQL and [1] I write a user defined function (CREATE FUNCTION) in JS (plv8) or Python (plpython). [1] assuming the update code needs to run inside the database, e.g. for performance reasons... otherwise just perform your update in the application, where you presumably have a richer library for manipulating data structures...
- jiripospisil 6y agoI don't remember the specific case (it's been a few years) but I do remember it had something to do with updating an array member. I googled around and found this [0] (the second question) which looks very similar. It's as simple as it gets - find an array member with "value" equal to "blue" and decrease its "qty". In MongoDB you can do that pretty easily ([1]) and the update should be atomic. The SQL version looks complicated and it's not even the form that you should use (notice the note about the race condition). Then again, maybe there's already a way to do that in PostgreSQL in a more elegant way, I assume the support has improved over the years. [0] https://dba.stackexchange.com/questions/193390/update-nth-element-of-array-using-a-where-clause https://dba.stackexchange.com/questions/193390/update-nth-el... [1] https://gist.github.com/jiripospisil/36f37a41f9b2c7fe74e841eb064be9d7 https://gist.github.com/jiripospisil/36f37a41f9b2c7fe74e841e...
- wlll 6y agoHow do you handle the data integrity issues that are present, even at the strongest configurable integrity levels, or is data integrity not an issue for your application?