为什么当mongodb的好处是无模式时,猫鼬会使用模式? [英] Why does mongoose use schema when mongodb's benefit is supposed to be that it's schema-less?

查看:73
本文介绍了为什么当mongodb的好处是无模式时,猫鼬会使用模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是mongodb的超级新手.我正在使用猫鼬从node.js访问mongodb,并且知道如何使事情正常工作,但是我不认为我为什么理解它的工作原理.

I am a super newbie to mongodb. I am using mongoose to access mongodb from node.js, and know how to get things to work, but I don't think I understand why it works the way it does.

最重要的是,当mongodb的突出特点之一是它没有模式时,我不明白为什么猫鼬会具有模式".有人可以启发我吗?谢谢.

Most importantly, I don't understand why mongoose has 'schema' when one of the standout features of mongodb is that it doesn't have schema. Could someone enlighten me? thank you.

推荐答案

没有模式的数据是无用的.您从MongoDB获得文档,该怎么做?阅读一些领域?您需要知道这些字段的名称,类型和含义.这是一个架构.

Data without a schema is useless. You get a document from MongoDB, what do you do with it? Read some fields? You need to know the names, types and meanings of those fields. That’s a schema.

当人们说MongoDB没有模式"时,他们实际上是说它不像SQL数据库那样强制执行模式. MongoDB将架构问题提升到您的应用程序级别,您可以在其中更灵活地处理它们.例如,为了向文档中添加新字段,您无需对集合执行全有或全无ALTER -可能需要数百万个条目.您只需将该字段添加到ODM(猫鼬)架构中即可.

When people say that MongoDB "has no schema", they really mean that it does not enforce schema the way SQL databases do. MongoDB pushes schema concerns up to your application level, where you can handle them more flexibly. For example, in order to add a new field to your documents, you don’t need to do an all-or-nothing ALTER on your collection—potentially millions of entries. You just add that field to your ODM (Mongoose) schema and you’re done.

这篇关于为什么当mongodb的好处是无模式时,猫鼬会使用模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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