OOP with MVC using Mongoose & Express.js OOP with MVC using Mongoose & Express.js mongoose mongoose

OOP with MVC using Mongoose & Express.js


As mongoose is specific to mongodb, this will be a hard task to abstract its behaviour.

The easiest way to do it is to set an interface for all ODMs and use an adapter pattern where mongoose is an "adaptee". Then, you can use a module providing some dependency injection to replace the used ODM.

As it is a really long task, I cannot give you some code. Moreover, it may be a pain to implement that kind of thing in javascript because it does not provide strong OOP natively. However, I can suggest you to take a look at some frameworks which can help you to do that like Danf for instance which provides a strong OOP paradigm with interfaces, classes, inheritance and a powerful dependency injection.