0
子文档领域给出一个文档这样比较两个MongoDB中
{
_id: '123456',
items: [{
itemId: 'abcd',
qty: 1
qtyMax: 2
}, {
itemId: 'defg',
qty: 3,
qtyMax: 3
}]
}
我想这个文件,因为items.qty < items.qtyMax
其中一个子文档匹配。
我知道$where
,但这里不适用,因为它需要手动编写整个验证,检查items
并循环遍历所有元素......我希望有更好的解决方案。
有没有太多的选择:$其中(https://docs.mongodb.com/manual/reference/operator/query/where/),[$ CMP(https://开头docs.mongodb.com/manual/reference/operator/aggregation/cmp/#_S_cmp),[map-reduce](https://docs.mongodb.com/manual/core/map-reduce/) –