gpt4 book ai didi

mongodb - MongoDB 的聚合引擎是运行在服务器还是客户端?

转载 作者:行者123 更新时间:2023-12-04 13:13:23 25 4
gpt4 key购买 nike

在设计基础架构时,我希望将尽可能多的处理放入应用程序服务器而不是数据库服务器 - 因为我的应用程序服务器可以更轻松地进行水平扩展。

因此,在考虑如何使用 MongoDB 时,我想知道 MongoDB 是否会利用客户端(应用程序服务器上的 mongo-client)的计算能力而不是数据库服务器的计算能力。我想象这沿着数据库服务器将所有文档(可能是后索引查找)发送到客户端,然后客户端将数据聚合到所需的结果。

我还没有找到任何文档来确认这是否可行,尽管我读到的内容似乎暗示所有聚合都是在数据库服务器上完成的。

所以我的问题是是否可以使用 mongoDB 客户聚合数据而不是 mogoDB 服务器

最佳答案

不要相信您将能够使用当前版本的 MongoDB 做到这一点。聚合管道始终运行在 mongod 进程之上,该进程在服务器上运行数据库软件。以前有一种特殊情况 - 分片集合和数据库 - 将聚合管道分成两部分,并在 mongos 进程上运行后半部分。如果这仍然是正确的,您可以在您的应用程序服务器上运行 mongos,并在您的应用程序服务器上运行至少部分聚合框架。

不幸的是,这在 2.6 版中发生了变化——它现在全部在分片上运行,并且不使用 mongos 进程。从文档:

Aggregation Pipeline and Sharded Collections

Behavior

Changed in version 2.6.

When operating on a sharded collection, the aggregation pipeline is split into two parts. The first pipeline runs on each shard, or if an early $match can exclude shards through the use of the shard key in the predicate, the pipeline runs on only the relevant shards.

The second pipeline consists of the remaining pipeline stages and runs on the primary shard. The primary shard merges the cursors from the other shards and runs the second pipeline on these results. The primary shard forwards the final results to the mongos. In previous versions, the second pipeline would run on the mongos. [1] Until all shards upgrade to v2.6, the second pipeline runs on the mongos if any shards are still running v2.4.



因此,您可以运行 2.4 版并使用 mongos 进程 - 或者将至少一个分片保留为 2.4 版并强制将处理交给 mongos。

关于mongodb - MongoDB 的聚合引擎是运行在服务器还是客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24283170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com