我们为什么需要,使用猫鼬有哪些优势 [英] Why do we need, what advantages to use mongoose

查看:72
本文介绍了我们为什么需要,使用猫鼬有哪些优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用mongodb,最近我经历了ODM框架Mongoose.

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

在文档中,我找不到为什么我们需要使用Mongoose的原因.我可以给出的一个原因是,我们可以从Mongoose定义应用程序架构.

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.

我正在寻找更多可能的原因,并且吸引我使用Mongoose的需求.

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

请列出使用Mongoose的所有可能的优点和原因/需要.

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

推荐答案

主要优势是相对于纯mongo的抽象.

Main advantage is abstraction over pure mongo.

许多来自SQL数据库类型的开发人员对于使用未定义结构的动态集合感到非常不舒服.因此,模式首先可以帮助实现这一目标.
此外,它实现了验证和其他简洁功能,以确保在插入/更新/查找集合中的文档时,您的架构是一致的.

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

它还会创建 Model 抽象,这使得使用起来更容易,因此看起来您正在使用的只是对象而不是纯数据.

It also 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 are many other goodies like middleware, plugins, population, validation. Please check mongoose docs for more information:

就个人而言,我更喜欢纯mongo,因为它与10gen mongo官方文档更加一致,并且不会创建抽象,而抽象总是会花费一些必须遵循的限制和规则.

Personally, I prefer pure mongo as it is more consistent with official 10gen mongo docs and does not create abstractions that always costs some limits and rules that you will have to follow.

这篇关于我们为什么需要,使用猫鼬有哪些优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆