Mongoose best practice with data layer in node application

looking at the nodejs node stack with nodejs / express and mongoose

What is considered the best solution?
(1) Creating a datamodel mongoose module, then working with model objects
(2) Creating a datalayer shell module that will use the mongoose model

Advantages for (1)
I really like OOP style classes, mongooses give me, add my own methods, my own setters and getters, I can add checks and event handlers and use the DataModel without overriding it in another module.

Advantages for (2)
I should be able to prototype a data layer with a simpler implementation (tests, etc.). or switch the database if necessary.

What do you think?

+5
source share
1 answer

Usually I start with the simplest and least difficult option to run and only move on to the more complex when it is really needed. Thus, in this case, I always start with Option 1 and have not yet found an instance where I would like me to start with Option 2. If I really need to change the databases, I will do the work then instead of doing more work in advance for something I will never need.

, , . ( ), . , .

+3

All Articles