Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suitability of MongoDB for certain use case?

Tags:

mongodb

nosql

I'm considering using MongoDB for a web application but I have read that there are some situations where it not recommended. I am wondering would my project be one of those situations.

Here's a brief outline of the entities in my system -

  • There are Users with standard user detail attributes
  • Each User can have many Receipts, a Receipt can have only one User
  • A Receipt contains many products
  • Products have standard product detail attributes
  • Users can have many Friends, and each Friend is a User themselves
  • Reviews can be given by Users for Products
  • There will be a Reputation system like the one here on stackoverflow where users earn Points and Badges

As you can see there are lots of entities that have various relationships with each other. And data integrity is important. Is this type of schema suitable for MongoDB?

like image 740
sonicboom Avatar asked Sep 19 '25 12:09

sonicboom


1 Answers

Your data seems to be very relational, not document-oriented.

You are also pointing out data integrity as an important requirement (I assume you mean referential integrity between different entities). When entities are not stored in the same document, it is hard to guarantee integrity between them in MongoDB. Also, MongoDB can't enforce any constraints (except for unique-ness of field values).

You also seem to have a very relational mind pattern overall which will make it hard for you to utilize MongoDB how it was meant to be used.

For these reasons I would recommend you to stick to a relational database.

The reason why you considered using MongoDB in the first place is likely because you heard that it is fast and that it scales well. Yes, it is fast and it does scale well, but only because it doesn't enforce referential integrity and because it doesn't do table joins. When you need these features and thus have to find ugly workarounds to simulate them, MongoDB won't be that fast anymore.

like image 95
Philipp Avatar answered Sep 22 '25 22:09

Philipp