News for hackers. Stuff that matters.
Re:Goodbye MongoDB, Hello PostgreSQL (2015) by technosamay20 on Thursday March 11, 2021 @03:04AM (#26421513)
There were many questions asking about recent experience with MongoDB. I have some recent experience so wanted to share with everyone.

My background:

2007-2010: Used MySQL to run a social network for 50M+ users. Would send 2B messages on peak days. All powered by Mysql.

2015-2020: Used Mongo to power a top 5k site. Zero downtime and dataloss in 5 years. Used Postgres for internal non user facing database

So I have familiarity with all of these databases at a decent scale. I am going to list pros and cons of each and why I would use. Again a tool is a tool. Just because I love a wrench, doesn't mean that I am going to use it instead of a hammer when I need to put some nails.

MongoDB:

They have come a long way since I started using them in 2012. If your use case is CRUD, you would be fine. There is still a lot of marketing fluff about sharding, multi document transactions etc which might not be fully reliable. I stay away from those things. But if you just use CRUD and you data can fit in a single db you are going to be fine at decent scale.

Following are some reasons I prefer Mongodb. It's possible that Postgres/MySQL has some of them even though I couldn't find them:

1. I don't like to manage schema migrations. During development you constantly add columns and it's a pain to make sure that this column is added to the sql databases on development, testing, staging, prod etc. With mongo, you just add a column and you are done.

2. No downtime on migrations: You can change you server type or mongo version with zero downtime. Did that since 6 years. Couldn't figure out how to do that with postgres (even with Aurora).

3. If you data structure fits document and subdocument schema, mongo is really easy to use. I tried jsonb with postgres and didn't find it as easy to use at mongo. If you data fits this paradigm, you can essentially get atomicity for multiple updates because they are all in a single document.

4. The admin interface of MongoDB Atlas is really development friendly. You can easily add read only replicas. You can easily add replicas in different regions. I shudder at the thought of managing Postgres myself and even Amazon Aurora is not as easy to admin as Atlas.

At this point I would consider Postgres only in the following case: If my data structure is like a non-tree graph. In that case I would expect to do multiple complex join and expect transaction consistency between tables.

If I am building a financial product which directly handles money or money instruments (bank, stock trading) I would definitely not use mongo for that.

Happy to answer followup questions.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by Jean-Philipe on Thursday March 11, 2021 @04:16AM (#26421969)
> With mongo, you just add a column and you are done.

No, usually you are not done. Your data doesn't have the column. So either you write your code in a way that it can handle the column being optional or you write code to read each document and add the column manually.

I've started out with mongodb on Fit Analytics originally, until we noticed at some point that our data was an inconsistent mess and we'd implement constraints in our back-end code to make sure the data is consistent. Eventually it became just easier to have an SQL database taking care of all those constraints, and we luckily migrated away.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by timewarrior on Thursday March 11, 2021 @11:36AM (#26425898)
Thanks for raising this good point. I didn't get a chance to elaborate on this in my original post because it was getting too long and it was end of a long day.

The cost of adding a column is zero, in terms of schema migration. So that helps with developer velocity. We used an ORM (mongoose), so that we can have added constraints including default values. But Mongo did help us avoid the friction of adding columns.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by Jean-Philipe on Friday March 12, 2021 @11:02AM (#26437165)
We also used mongoose, which is awesome. In retrospect, I actually wish we had kept mongodb as a read-only database and used postgres as the source of truth. Our data was mostly read-only, with some rather complex relations behind the scenes.

For quick prototypes, I still prefer mongodb.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by fhunt on Thursday March 11, 2021 @05:52AM (#26422624)
> our data was an inconsistent

Because you didn't put strict validation before data entered Mongo and I guess you didn't use a typed lang which makes such a validation like a no-brainer and quite natural.

SQL gives you type checking for free, Mongo does not. However, if you have a typed lang and have a proper validation in place you just have to define those at one place and not in the database and in your app (DRY).

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by threeseed on Thursday March 11, 2021 @03:20AM (#26421616)
> Happy to answer followup questions.

This thread is like a piñata that gets pulled out every 6 months or so take a wack at MongoDB and talk about how everyone should just use PostgreSQL for every database problem no matter whether it's relational or not.

No-one cares about whether MongoDB is useful or not.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by tommilukkarinen on Thursday March 11, 2021 @03:59AM (#26421847)
"This thread is like a piñata"

Cudos for having master class control of the word. My favorite punch bag are play stores, root of all evil.

A list of cycling subjects that split opinions about 50-50 in this news group would be hilarious.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by timewarrior on Thursday March 11, 2021 @11:39AM (#26425940)
I have been watching these threads forever. I personally like Mongo and wanted to added some real life perspective to it.

In the end it is a tool which fits some scenarios.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by jackdh on Thursday March 11, 2021 @03:41AM (#26421733)
>You can change you server type or mongo version with zero downtime.

How so? All the documentation on upgrading say you need to shutdown each instance to then step up to the next minor level.

For instance 3.4 -> 3.6 -> 4.0 etc.

https://docs.mongodb.com/manual/release-notes/4.0-upgrade-st...

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by synthmeat on Thursday March 11, 2021 @04:33AM (#26422081)
If you're using replica set, as you should for anything other than development (and even in development, sometimes you need a replica set for some features), you just sequentially upgrade each one. It goes down, clients figure out the new topology and continue working.

I'm also running on MongoDB, top 6k site and while I wouldn't say there weren't any issues, uptime is wonderful, I sleep well, and have zero problems with modeling the domain as a document collections instead of relational. Can easily imagine that it would not be great fit for many other use cases. Not using Atlas as GP, so it's more work, but I'm trying to be scrappy.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by timewarrior on Thursday March 11, 2021 @11:38AM (#26425919)
You are correct. This was in the case of replica set.

Are you running Mongo yourself. I use to be at MLab, but Mongo Atlas is really good. Give it a shot!

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by girishso on Thursday March 11, 2021 @04:07AM (#26421904)
> If I am building a financial product which directly handles money or money instruments (bank, stock trading) I would definitely not use mongo for that.

My friend used to work for citi bank, his team managed high value transactions (in billions). I was _stunned_ to hear that they were storing all their data in MongoDB.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by timewarrior on Thursday March 11, 2021 @11:42AM (#26425976)
I am not sure what is the exact use case. They could be using it for a non-critical data warehouse which could easily be recreated.

If you can deterministically determine your use case and are confident that mongo will fit it - it might be a good idea.

My concern which mongo is that is if you push the feature set, it will start falling apart at the seams.

Even though Postgres/MySql have some issues which can reduce the velocity of your team, if you absolutely want to be sure about data integrity and want full flexibility of evolving use case, they might serve better than mongo.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by girishso on Friday March 12, 2021 @02:06AM (#26432954)
> I am not sure what is the exact use case. They could be using it for a non-critical data warehouse which could easily be recreated.

They decided to port the existing project to .NET and used MongoDB (just because the .NET team thought it's cool) to store _all the data_, I'm pretty sure of it. My friend was not part of the .NET team.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by creshal on Thursday March 11, 2021 @04:12AM (#26421946)
Citibank is a leading expert in losing your money, MongoDB is a perfect fit for their business model.
Re:Goodbye MongoDB, Hello PostgreSQL (2015) by thesimon on Thursday March 11, 2021 @03:57AM (#26421835)
> During development you constantly add columns and it's a pain to make sure that this column is added to the sql databases on development, testing, staging, prod etc. With mongo, you just add a column and you are done.

I have found liquibase (https://www.liquibase.org/) to be extremely helpful for this.

Re:Goodbye MongoDB, Hello PostgreSQL (2015) by timewarrior on Thursday March 11, 2021 @11:46AM (#26426030)
Thanks, I will take a look at it. It looks really expensive though!
Re:Goodbye MongoDB, Hello PostgreSQL (2015) by menzoic on Thursday March 11, 2021 @04:08AM (#26421910)
Why do you consider sharding to be marketing fluff? If your dataset was big enough wouldn't that be a requirement for your database?
Re:Goodbye MongoDB, Hello PostgreSQL (2015) by timewarrior on Thursday March 11, 2021 @11:44AM (#26425999)
I meant mongo support for sharing might be marketing fluff. As in they promise it works but it might be unreliable.

I have come to trust Mongo with CRUD on a document. Rest of the features might not work as well. Looks at the recent Jespen test for mongo ( https://jepsen.io/analyses/mongodb-4.2.6 )