DEV Community

Discussion on: Mongodb-native over mongoose?

Collapse
 
yentsun profile image
Max Korinets

I actually stopped using MVC (also ORMs, also OOP) after a couple of years developing on Node.js.

My life got much easier since then and I never looked back.

Thread Thread
 
rpajf profile image
Raphael Portela

What do you use , instead of MVC? i dont use OOP in front end, but in the backend i only know how to develop using classes

Thread Thread
 
yentsun profile image
Max Korinets • Edited

I was using Seneca (microservice framework) and it changed my mindset in the first place. Your microservice has endpoints (HTTP, AMQP, MQTT, even TCP, whatever) and these endpoints handle whatever comes to them. Period. If you need to abstract logic (i. e. for example not call DB directly from endpoint handler) - you abstract it with functions. I also learned that HTTP(REST) is not the only protocol out there but most MVC frameworks consider it such. In fact its rather primitive, but probably most commonly used one, okay.

Later I started designing non-micro services (monoliths) as if they were Seneca's microservices. Flat structure, no hierarchy, no classes - just endpoint handlers or 'C' in MVC and some internal services (you probably heard of services in MVC too, when Model methods are not enough - btw thats when I started to doubt MVC).

And later I realized that our backends in general are just I/O brokers / mediums. They listen to endpoints, handle the calls by just calling other internal / external services (DB, Redis, SendGrid, Stripe) and respond. Yes - call to a DB is no different from a call to Sendgrid or a call to any other API. In MVC you think database and the Model is something special.

As I remember MVC comes from Java where you can't do anything without a class or interface but for some reason it had spread to other languages.

Here is an example I only have in the open: gitlab.com/venture-api/gate/tree/d....

(Maybe I need to write an article on this to get my thoughts and experience organized)

Thread Thread
 
rpajf profile image
Raphael Portela

Thank you so much for such a complete and elucidating answer. I started programming in june of 2019, im focused on node, ReactJS(using hooks) and React Native, I use sequelize in the backend, and yes, on MVC when your controller is getting too big, the creation of aditional services is required. I started learning mongoose this week and i saw that the comands were not so different from the ones on MongoDB itself, unlike sequelize(the most known ORM), and then i landed on this page. I saw your code on gitlab, its very different from what im used to do, i will gitclone and explore this example, but what do you suggest me doing? stick to mvc a bit? learn mongo, learn pure SQL, maybe flutter in the end of 2020?

Thread Thread
 
yentsun profile image
Max Korinets • Edited

Surprisingly I'm doing some frontends right now and use React Hooks too :) I'd say Hooks is a beautiful piece of technology (rarely seen nowadays) and I'm really excited about it!

My advice will probably be:

  • if you joined an existing project - you won't have the luxury to get away from MVC in near future as employers consider it a standard and you will have to do it
  • don't forget that there is something else, try non-MVC on a pet project
  • dig CQRS + Event Sourcing (until you fully understand what it is, seriously) - this will be a revelation, also altering your mindset a bit
  • after digesting CQRS/ES, you will likely discover that MongoDB (in its initial state, no schemas) is an ideal read-only 'projection' storage rather than general data storage. It looks like being under pressure by the industry, so it tries to be a general data storage. Emerging of Mongoose is probably the result of this pressure too :)
  • Postgres (or other flavours of SQL-based storages) on the other hand, is a better general data storage - schematize your data to your heart with the variety of types
  • haven't tried Flutter but I have strong confidence in React Team, I'd probably prefer their stuff. I haven't touched mobile development yet though :)