why do we need, what advantages to use mongoose

Posted 都市烟火

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了why do we need, what advantages to use mongoose相关的知识,希望对你有一定的参考价值。

question:

I have just started up with mongodb and i recently gone through Mongoose, an ODM framework.

On the documentation, i couldn‘t find why we need to use Mongoose. One reason i can give is we can define application schema from Mongoose.

I am looking for more possible reasons, and needs that will attract me to use Mongoose.

Please list all possible advantages and reasons/needs why use Mongoose.

some voice:

(1)、Main advantage is abstraction on top of pure mongo.

Many developers come from SQL database types, and feel very uncomfortable working with dynamic collections that have no any structure defined. So Schemas in first place helps with that.
Additionally to that it implements validation and other neat features in order to make sure your schema is well satisfied when inserting/updating/finding documents from collections.

It as well creates Model abstraction which makes it easier to work with, so it looks like you are working with just objects rather than pure data.

There is more concepts like middlewarepluginspopulationvalidation and more, please check here: http://mongoosejs.com/docs/guide.html

Personally, I prefer mongo-native as it is more consistent with official 10gen mongo docs and does not creates abstractions that always cost of some limits and rules that you will have to follow.

(2)、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:

1)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.

2)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 encapsulated with a model. Encapsulation is especially hard initially - unless you have a very clear idea of 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).

参看:https://www.quora.com/Node-js/Node-js-Whats-the-advantages-of-using-MongoDB-Mongoose

以上是关于why do we need, what advantages to use mongoose的主要内容,如果未能解决你的问题,请参考以下文章

Hadoop Illuminated——Chapter3 Why do I Need Hadoop?

Why do you need a new Launch X431 scan tool?

How much do we need to learn to be a Self-driving Car Engineer?

What makes an inferred latch? how To avoid creating inferred latches? when do you know you need lat

Why containers? Why should we care?

But what exactly do we mean by "gets closer to"?