在具有标题为兴趣的数组字段的mongo数据库中,
当我需要寻找对柔道或mma感兴趣的人时,我可以这样编写查询:{interests : {$regex: "judo|mma", $options: 'i'}}
我如何找到对柔道和mma感兴趣的人?
注意:
我已经尝试了以下方法以及这些方法的各种变体,但是似乎都没有用:
{interests : {$regex: "(?=judo)(?=mma)", $options: 'i'}},
{interests : {$regex: "(?=.*judo)(?=.*mma)", $options: 'i'}}
谢谢。
最佳答案
这样的事情应该工作:
{interests: {$all: [/^judo$/i, /^mma$/i]}
关于node.js - mongodb正则表达式中的AND运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59841062/