带有$lookup和$match的MongoDB聚合管道非常慢

带有$lookup和$match的MongoDB聚合管道非常慢,mongodb,Mongodb,我试图使用mongoDb聚合管道来查找其他表,并检查是否匹配某些属性 我的查询如下(p.s.bigtable被切分): 我已经为bigtable.user\u代码、user.code和user.country创建了索引。但是查询速度非常慢。我试着解释了,这是COLLSCAN 您知道$match with foreign table中是否不支持索引吗?为什么不在user集合上运行聚合管道,您可以在其中放置适当的索引,例如在country字段上,然后在筛选的文档(即db.user.aggregate

我试图使用mongoDb聚合管道来查找其他表,并检查是否匹配某些属性

我的查询如下(p.s.bigtable被切分):

我已经为bigtable.user\u代码、user.code和user.country创建了索引。但是查询速度非常慢。我试着解释了,这是COLLSCAN


您知道$match with foreign table中是否不支持索引吗?

为什么不在
user
集合上运行聚合管道,您可以在其中放置适当的索引,例如在
country
字段上,然后在筛选的文档(即
db.user.aggregate)([{$match:{“country”:“US”}{$lookup:{from:“bigtable”,localField:“code”,foreignField:“user_code”,as:“bigtable”}},])
?bigtable在shard中,因此,它不能作为外来表用于查找。您可以展示解释告诉您的内容吗?为什么不在
用户
集合上运行聚合管道,在那里您可以放置适当的索引,例如在
国家
字段上,然后在过滤文档,即
db.user.aggregate([{$match:{“country”:“US”}}}{$lookup:{$from:“bigtable”,localField:“code”,foreignField:“user_code”,as:“bigtable”}},])
?bigtable在shard中,因此,它不能作为外部表在查找中使用。您能展示解释告诉您什么吗?
 db.bigtable.aggregate( [  
    {$lookup:{ from: "user", localField:
               "user_code", foreignField: "code",as: "user"}},   
    {$match: {"user.country":"US" } }] )