【发布时间】:2018-07-28 14:29:48
【问题描述】:
我有一个集合,其中投资是 mongodb 文档中的一个数组。现在使用聚合,我试图过滤投资长度超过 5 倍的结果,然后使用匹配查询进行下一个处理。
Collection{
_id:000000
---------------------
"investments" : [ {
hhhhhhhhhhhhhh
},
{
hhhhhhhhhhhhhh
} }]
-----------------
我在下面写的匹配查询不起作用。任何建议:
db.companies.aggregate( [
{ $match: {"founded_year" : 2004},
{ "investments" : {$size: : { $gte: 5 } } } },
----------------------------------
--------------------------------
]}
【问题讨论】:
-
看看这个helps
-
你可以在3.6中使用
db.companies.find({"$expr":{"$and":[{"$eq":["$founded_year", 2004]}, {"$gte":[{"$size":"$investments"}, 5]}]}})
标签: mongodb aggregation-framework