在一个带有名为“interests”的数组字段的 mongo 数据库中, 当我需要寻找对柔道或综合格斗感兴趣的人时,我会这样编写查询:
{兴趣:{$regex: "judo|mma", $options: 'i'}}
如何找到对柔道和综合格斗感兴趣的人?
注意: 我已经尝试了以下方法和这些方法的各种变体,但似乎都不起作用:
{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/