'Why should we use mongoose ODM instead of using directly Mongodb with mongodb driver for Nodejs/Express? [closed]
I have just started up with mongodb and I recently gone through Mongoose, an ODM for MongoDb.
On the documentation, I couldn't find why we need to use Mongoose instead of using Mongodb directly except one reason which is we can define application schema from Mongoose. Pls provide all other reasons of using moongose:
Solution 1:[1]
If you are working with Node.js and you are pretty new NoSQL I'd recommend using the the native Node Driver(mongodb) at first.
Reasons:
The syntax between the Node Driver and the Mongo shell is very similar and so you'll get a quicker grasp of how to use MongoDB in general.
Models are only useful when you are scaling into a big application with a large API that needs to be broken up into a MVC system(mongoose being your models).
Pros/Cons of using Mongoose:
Pros:
- Biggest Pro is that it has the data validation built into it(requirements of what data you will allow to be added or to update your database). It will take some work to build that yourself.(but not THAT hard)
- It will abstract away most of the mongoDB code from the rest of the application.
Cons
Biggest con is starting off with schemas right out of the gate will really defeat the purpose of using NoSQL and it will be hard to experience what is good about having a loose structured data system during the stages of rapid development.
Not all of your data operations will nicely fit into a characterization that can be encapsulated with a model. Encapsulation is especially hard initially - unless you have a very clear idea of the data flow before you start (which is ideal, but not easy when you are building something conceptually new and requires a lot of experimentation and change/redesign).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stephen Rauch |
