MongoDB将通过$ lookup聚合运算符使用分片 [英] MongoDB to Use Sharding with $lookup Aggregation Operator

查看:720
本文介绍了MongoDB将通过$ lookup聚合运算符使用分片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$lookup是MongoDB 3.2中的新增功能.它对同一数据库中未分片的集合执行左外部联接,以从联接"的集合中筛选文档以进行处理.

$lookup is new in MongoDB 3.2. It performs a left outer join to an unsharded collection in the same database to filter in documents from the "joined" collection for processing.

要使用$lookup,不能对from集合进行分片.

To use $lookup, the from collection cannot be sharded.

另一方面,分片是一种有用的水平缩放方法.

On the other hand, sharding is a useful horizontal scaling approach.

一起使用它们的最佳实践是什么?

What's the best practise to use them together?

推荐答案

正如引用的文档所示,您不能在分片集合上使用$lookup.因此,最佳实践的解决方法是在单独的查询中自行执行查找.

As the docs you quote indicate, you can't use $lookup on a sharded collection. So the best practice workaround is to perform the lookup yourself in a separate query.

  1. 执行您的aggregate查询.
  2. 可能使用find查询
  3. 将结果合并为所需的任何格式.
  1. Perform your aggregate query.
  2. Pull the "localField" values from your query results into an array, possibly using Array#map.
  3. Perform a find query against the "from" collection, using a query like {foreignField: {$in: localFieldArray}}
  4. Merge your results into whatever format you need.

不要让$lookup限制阻止您对需要扩展性的集合进行分片,而要自己执行查找功能.

Don't let the $lookup limitation stop you from sharding collections that require it for scalability, just perform the lookup function yourself.

这篇关于MongoDB将通过$ lookup聚合运算符使用分片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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