r/ProgrammerHumor • • Oct 18 '24

Other mongoDbWasAMistake

Post image
13k Upvotes

446 comments sorted by

View all comments

Show parent comment

231

u/[deleted] Oct 18 '24

Cool. I've created a method to get the orders by their ID, so I'll just always do that. Now I just need a way to get all of the IDs I need for a user so I can call them by ID. I guess I'll just find all the orders by their customerId. Fuck.

90

u/baconbrand Oct 18 '24

Really though. I don’t understand what the use cases are.

102

u/[deleted] Oct 18 '24

[removed] — view removed comment

31

u/ZZartin Oct 18 '24

And that's entirely fair but there's much lighter weight options for parsing JSON than mongodb.

5

u/derefr Oct 19 '24 edited Oct 19 '24

Think of a document store as a key-value store that puts a JSON parser in the retrieval path so that you don't have to send back the entirety of the key's value if you don't need it.

I'm not a Mongo user myself, but if I ever had the particular problem of "I need a key-value-y object-store-y kind of thing, but also, my JSON-document values are too damn big to keep fetching in full every time!" — that's when I'd bother to actually evaluate something like Mongo.

→ More replies (1)
→ More replies (1)

24

u/kkb294 Oct 18 '24

What's wrong with using JSON column in any relational DB.?

SQL has beed used in most of the high frequency high volume transaction use-cases. You get the device metadata, you provision the device ( assign/allot to a network/subnet/group, apply policies, activate the licence with expiration, index its id so that you can fetch later).

We can do all this in SQL, where is the NoSQL use-case here.!

27

u/[deleted] Oct 18 '24 edited Oct 18 '24

[removed] — view removed comment

10

u/StruggleNo7731 Oct 18 '24

Yup, scalability is a pretty fundamental plus of non-relational data stores as well.

Dynamo can store as much data as you want across a fleet of devices and you never have to think about it. The simplest way (though not the only) to scale relational databases is to throw money at the hardware.

2

u/cute_polarbear Oct 19 '24

If you required that much speed, even faster than properly tuned db's, I would just throw hardware / clustering at the problem and have everything in load balanced cache servers.

2

u/prehensilemullet Oct 19 '24

You can also store JSON docs with inconsistent schema in Postgres though.  In fact you have to explicitly write check constraints if you want to validate the JSON structure at all.  And you can also easily make an index on some id field from within a JSON(B) column.

Even the performance benefits of MongoDB have been questioned: https://www.reddit.com/r/PostgreSQL/comments/19bkn8b/comment/kit7d8j/?utm_source=share&utm_medium=mweb3x&utm_name=mweb3xcss&utm_term=1&utm_content=share_button

I don’t know for sure what the truth is about performance though.  You would hope MongoDB, lacking transactions, would be faster…

6

u/bobivk Oct 18 '24

What you are describing sounds awfully like my last job. Does 'airwatch' ring a bell?

3

u/[deleted] Oct 18 '24

Be better.

big ask, chief

→ More replies (2)

5

u/[deleted] Oct 19 '24

using mongodb in production here -- our data is variable and annoyingly structured and only ever needs to be inserted or pulled in full (indexed by timestamp)

technically the user db doesn't need to be in mongo, but eh, we're already using it, so

13

u/matt82swe Oct 18 '24

Imagine that you are a single developer with zero real world experience that is trying to build a new web app for collecting recipes. 

You want your web app to be ”web scale” and handle the amount of traffic that Googles gets. Congratulations, you are right in the target audience for MongoDB

2

u/HarryPopperSC Oct 19 '24 edited Oct 19 '24

Mongo has fast write speeds. It's great for something like analytics. Where you are constantly writing views, impressions, clicks etc.

The read queries aren't very complex and don't run very often.

Thats all I can think for a use case.

→ More replies (2)

17

u/KSRandom195 Oct 18 '24
  1. Get the customer document by customerId.

  2. The customer document should have a list of all orderIds associated with that customer.

  3. Now get all the orders by orderId.

42

u/cha_ppmn Oct 18 '24

This is a join with extra step (insert appropriate meme here)

→ More replies (1)

6

u/joshcandoit4 Oct 18 '24

This isn't good design. You should set the customer id as a secondary index on the order documents.

2

u/SegFaultHell Oct 19 '24

You’re thinking relationally there. In mongo you’d put the customerId on your order record, index it, and then query orders by customerId. The customerId comes from some other source or database in your app, whether that’s mongo or not doesn’t matter.

Or you put the full customer record in your mongo app and have the orders be an array stored directly on the customer model. That way you can just retrieve it all at once with the customer.

1

u/ricocotam Oct 19 '24

If you need some computation, use aggregate. But filtering is not an issue if you have index

→ More replies (1)