我有一个收藏品,其中投资是 mongodb 文档内的数组。现在,我正在使用汇总来过滤投资长度超过 5 倍的结果,然后使用匹配查询进行下一步处理。
Collection{
_id:000000
---------------------
"investments" : [ {
hhhhhhhhhhhhhh
},
{
hhhhhhhhhhhhhh
} }]
-----------------
我写的匹配查询如下,但不起作用。有什么建议吗:
我写的匹配查询如下,但不起作用。有什么建议吗:
db.companies.aggregate( [
{ $match: {"founded_year" : 2004},
{ "investments" : {$size: : { $gte: 5 } } } },
----------------------------------
--------------------------------
]}
db.companies.find({"$expr":{"$and":[{"$eq":["$founded_year", 2004]}, {"$gte":[{"$size":"$investments"}, 5]}]}})
。 - s7vr