Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoose best-practice with data layer in node application [closed]

looking into the nodejs server stack with nodejs/express and mongoose

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

Pros for (1)
I really like the OOP style classes mongoose gives me, add my own methods, my own setters and getters, I can add validation and event-handlers, and use the DataModel without redefining it in another module.

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

What do you think?

like image 332
Paul Avatar asked Apr 30 '12 01:04

Paul


1 Answers

I usually start with the easiest and least complex option to start and only move to a more complex one when it's really needed. So in this case I always start with Option 1 and have yet to find an instance where I wish I had started with Option 2. If I really need to change databases, I'll do the work then instead of doing more work upfront for something I may never need.

Keep in mind that this depends on how big of a project it is and how many people are working on it. If it's a small team (or just you) extra layers of abstraction generally aren't needed. If it's a large project with a large team, I'd take a bit longer figuring out the best architecture for long term maintainability.

like image 81
Bill Avatar answered Nov 13 '22 23:11

Bill