【发布时间】:2021-04-05 15:25:35
【问题描述】:
作为输入,我得到一个搜索查询(should 运算符)和一个过滤器(关于是否喜欢帖子,must/mustNot 运算符)。
我从以下内容开始,作为我的聚合管道的基础:
{ $search: { compound: {} } }
然后,如果给出查询,我会添加:
$search.compound.should.push({
text: {
query: q,
path: ["data.displayName"],
score: {
boost: {
value: 5,
},
},
},
// Plus others
});
现在,每个帖子都有一个likes 数组。我只想在likes 中选择包含特定字符串的帖子,如果可能的话,在compound.must/mustNot 下。
我想避免在计算机上加载数据并在本地过滤文档(我为整个数据库付费,我使用整个数据库!)。如果在聚合管道中无法进行数组操作,那还有什么替代方法?我仍然对文档以及应该在哪里使用运算符感到困惑。
【问题讨论】:
标签: mongodb mongodb-query mongodb-atlas mongodb-atlas-search