MongoDB聚合vs Mongoose虚拟 [英] MongoDB aggregation vs Mongoose virtuals

查看:59
本文介绍了MongoDB聚合vs Mongoose虚拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章中,我了解到mongoose围绕MongoDB创建了一个框架会以其他方式查询其中的一些信息.

From this post I have understood that mongoose has created a framework around MongoDB that does some of it queries in a different way.

我已经阅读了有关填充虚拟机的信息.当您可以使用它们来获得所需的结果时,它们相对于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? When should you use one over the other?

推荐答案

猫鼬:这是一个围绕MongoDB的非常好的框架,它使与MongoDB的协作变得容易,因为大多数事情都是由Mongoose内部管理的.Populate Virtuals是框架的一部分,然后将使您能够在驱动程序级别解决基本的实体关系.

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. Populate Virtuals is part of the framework and then will allow you to have basic entity-relationship resolved at driver-level.

聚合框架:是一项更高级的功能,您可以将其视为一种查询语言(实际上就是这种语言),您可以在其中创建在数据库级别解决的基本,中等,高级查询(这在性能方面存在巨大差异).而不是仅仅获取"消息.使用$ lookup处理某些数据,您还可以过滤数据或按某些键进行分组.您无法使用虚拟机进行的操作.

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). Rather than just "fetch" some data with $lookup, you can also filter the data or grouping by some key. Something you can't do with virtuals.

一般来说,您可以认为Aggregation Framework是在MongoDB中编写面向性能查询的一种非常干净且可扩展的方法,因为整个管道都是在 DB级上解决的.而不是驱动程序级别.

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.

注意:聚合表达式也可以用作findAndModify更新管道的一部分,这意味着您可以使用管道来计算查找并更新数据(这是虚拟机无法做到的).

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

注意:即将发布的MongoDB 4.4版本还将在find()中引入聚合表达式,这使聚合语法成为您编写查询的很好的投资.

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聚合vs Mongoose虚拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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