简体   繁体   English

MongoDB 聚合与 Mongoose 虚拟

[英]MongoDB aggregation vs Mongoose virtuals

From this post I have understood that mongoose has created a framework around MongoDB that does some of it queries in a different way.这篇文章中,我了解到 mongoose 围绕 MongoDB 创建了一个框架,它以不同的方式执行其中一些查询。

I have read about populate virtuals .我读过有关填充虚拟的内容。 When you can use them to get your desired results, what advantages and disadvantages do they have over MongoDB aggregations?当您可以使用它们来获得所需的结果时,它们与 MongoDB 聚合相比有哪些优点和缺点? When should you use one over the other?什么时候应该使用其中一种?

Mongoose: is a very good framework around MongoDB that make it easy to work with MongoDB because most of the things are managed internally by Mongoose. ZCCADCDEDB567ABAE643E15DCF0974E503Z:是围绕 MongoDB 的一个非常好的框架,可以轻松使用 MongoDB,因为大部分事情都是由 ZCCADDEDB56774503EZCCADDEDB5674543EZCADEDB03 内部管理的。 Populate Virtuals is part of the framework and then will allow you to have basic entity-relationship resolved at driver-level.填充虚拟是框架的一部分,然后将允许您在驱动程序级别解决基本的实体关系。

Aggregation Framework: is a more advanced feature, you can think it as a query language (actually, it is) where you can create basic, medium, advanced query that are resolved at DB-level (this is huge difference in terms of performance).聚合框架:是一个更高级的功能,您可以将其视为一种查询语言(实际上是这样),您可以在其中创建在 DB 级别解析的基本、中等、高级查询(这在性能方面存在巨大差异) . Rather than just "fetch" some data with $lookup, you can also filter the data or grouping by some key.您不仅可以使用 $lookup “获取”一些数据,还可以通过某个键过滤数据或分组。 Something you can't do with virtuals.虚拟机无法做到的事情。

As general point, you can think Aggregation Framework as a very clean and extendible way to write performance oriented query in MongoDB since the whole pipeline is resolved at DB-level rather then driver-level.一般来说,您可以将聚合框架视为在 MongoDB 中编写面向性能的查询的一种非常干净且可扩展的方式,因为整个管道是在DB 级别而不是驱动程序级别解决的。

NOTE: Aggregation Expressions can be also used as part of findAndModify update pipeline, that means you can compute a find and update the data by using a pipeline (something you can't do with virtuals).注意:聚合表达式也可以用作 findAndModify 更新管道的一部分,这意味着您可以使用管道计算查找和更新数据(这是您无法使用虚拟程序执行的操作)。

NOTE: Upcoming version of MongoDB 4.4 will also introduce Aggregate Expressions in find(), that make the aggregate syntax a good investment for write you query.注意:即将发布的 MongoDB 4.4 版本还将在 find() 中引入聚合表达式,这使得聚合语法成为编写查询的良好投资。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM