Reputation: 6609
I asked this as a specific question within the context of using mean stack.(It might be naive question because I am new to Mean Stack) I have seen example of using mongoose to map mongodb into objects. I was wondering the benefits of that.
In my understanding, there is benefits of saving a blob of json into mongodb without worry about the schema of the data. And then you have your Angular client app (single point) to define and use the data object. This seems to me already a valid/nice application.
So why mongoose approach? Isn't it in conflict? Your client is already aware of the data model so to present it to the user, why define it again on the server(express) side again (mongoose object mapping)?
Upvotes: 0
Views: 964
Reputation: 284
I did not understood your question properly, but I hope this helps, Mongoose is a ODM as rightly pointed by @Wasiq as it provides a middleware between Nodejs(Backend) and Database(MongoDB). Why do we use it?
1) One of the reasons is: It defines the schema(structure of documents within a collection and models are used to create instances of data that will be stored in documents). And since, MongoDB is NOSQL, it is schema free. For the developers coming from conventional dbs, this is a big help.
2) The best thing about Mongoose for MongoDB is the fact that you can have built-in automatic validation of the data which you are inserting/updating.
Or you can use Node Driver and write your queries alternatively, then you dont need to worry if ever your schema changes.
Upvotes: 1
Reputation: 3118
Mongoose is an Object Data Modeling
that support NodeJs
through which we connect to mongodb.On server side you want to query for mongo
in more organized and structured way. Mongose have schema and models for restricting data redundancy as compared to native mongo
driver there are many ODM
available use can use different like monk
etc.
In Angular we make service to communicate with our server it doesn't concerned with data model for we know about request
and response
that will receive.
Upvotes: 0