gpt4 book ai didi

node.js - mongodb 正则表达式中的 AND 运算符

转载 作者:太空宇宙 更新时间:2023-11-03 23:49:48 27 4
gpt4 key购买 nike

在一个带有名为“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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com