如何使用MongoDB聚合匹配两个列表

如何使用MongoDB聚合匹配两个列表,mongodb,aggregation-framework,pymongo,Mongodb,Aggregation Framework,Pymongo,我收集的资料如下: col1 {"_id":"5c3ea35651166f3refsfd5", "environment": "production", "application": ['cloud', 'android', 'finance']}, {"_id":"5c3ea35651166f3refsfd6", "environment": "production", "application": ['banking', 'network', 'finance']} 我只想在集合中的应用

我收集的资料如下: col1

{"_id":"5c3ea35651166f3refsfd5",
"environment": "production",
"application": ['cloud', 'android', 'finance']},

{"_id":"5c3ea35651166f3refsfd6",
"environment": "production",
"application": ['banking', 'network', 'finance']}
我只想在集合中的应用程序与['cloud','database','booking']列表中的应用程序匹配时投影数据。在这种情况下,我应该只能得到第一个文档,因为它在文档和列表中都有“云”

我需要使用聚合。但是我没有得到正确的方向。

您可以使用查询运算符

col1.aggregate([
  { '$match': { 'application': { '$in': ['cloud', 'database', 'booking'] }}},
  { '$project': { 'environment': 1, 'application':1 }}
])

但是列表中的值会根据用户的不同而变化,所以我不应该使用固定列表。您可以动态放置
lst
数组。哦!我的错。非常感谢。