mongodb正则表达式中的AND运算符

问题描述 投票:1回答:1

在具有标题为兴趣的数组字段的mongo数据库中,当我需要寻找对柔道或mma感兴趣的人时,可以这样编写查询:

{interests : {$regex: "judo|mma", $options: 'i'}}

我如何找到对柔道和mma感兴趣的人?

注意:我已经尝试了以下方法以及这些方法的各种变体,但似乎都没有用:

{interests : {$regex: "(?=judo)(?=mma)", $options: 'i'}},
{interests : {$regex: "(?=.*judo)(?=.*mma)", $options: 'i'}}

谢谢。

node.js regex mongodb mongodb-query regex-lookarounds
1个回答
1
投票

类似的东西应该可以工作:

{interests: {$all: [/^judo$/i, /^mma$/i]}
© www.soinside.com 2019 - 2024. All rights reserved.