mongodb 正则表达式中的 AND 运算符
AND operator in mongodb regex
在一个 mongo 数据库中有一个名为 interests 的数组字段,
当我需要寻找对柔道或综合格斗感兴趣的人时,我会这样写查询:
{interests : {$regex: "judo|mma", $options: 'i'}}
我如何找到对柔道和综合格斗感兴趣的人?
注意:
我已经尝试了以下和这些的各种变体,但 none 似乎有效:
{interests : {$regex: "(?=judo)(?=mma)", $options: 'i'}},
{interests : {$regex: "(?=.*judo)(?=.*mma)", $options: 'i'}}
谢谢。
像这样的东西应该可以工作:
{interests: {$all: [/^judo$/i, /^mma$/i]}
在一个 mongo 数据库中有一个名为 interests 的数组字段, 当我需要寻找对柔道或综合格斗感兴趣的人时,我会这样写查询:
{interests : {$regex: "judo|mma", $options: 'i'}}
我如何找到对柔道和综合格斗感兴趣的人?
注意: 我已经尝试了以下和这些的各种变体,但 none 似乎有效:
{interests : {$regex: "(?=judo)(?=mma)", $options: 'i'}},
{interests : {$regex: "(?=.*judo)(?=.*mma)", $options: 'i'}}
谢谢。
像这样的东西应该可以工作:
{interests: {$all: [/^judo$/i, /^mma$/i]}