最近,我正在研究聚合管道的性能优化。我在决定索引时遇到了这个问题。我为{'receiverId': 1,'type': 1 }设置了一个复合索引。我原来的管道是这样的。我正在考虑是否有必要对isRead进行索引。我之所以没有创建三个字段的复合索引,因为其他查询只使用recieverId和type。
notifications.aggregate([{
$match: {
'recieverId': ObjectId(xxx),
'type': xxx,
'isRead': false
}
},
{
...
},
], (err, result) => {
return res.status(200).json(result);
});所以,我换了下面这个。想知道这样的管道在过滤recieverId和type后是否可以节省一些计算成本。isRead,第二个$match会从第一个$match的结果中过滤吗?
notifications.aggregate([{
$match: {
'recieverId': ObjectId(xxx),
'type': xxx,
}
},
{
$match: {
'isRead': false
}
},
{
...
},
], (err, result) => {
return res.status(200).json(result);
});发布于 2019-06-10 15:45:17
https://stackoverflow.com/questions/56528845
复制相似问题