Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex “如何做”;“ab非dc”;mongodb中的正则表达式搜索_Regex_Node.js_Mongodb - Fatal编程技术网

Regex “如何做”;“ab非dc”;mongodb中的正则表达式搜索

Regex “如何做”;“ab非dc”;mongodb中的正则表达式搜索,regex,node.js,mongodb,Regex,Node.js,Mongodb,我需要在一个条件为“ab not dc”的字段上进行正则表达式基搜索。下面是查询结果错误。建议使用一个适当的查询 db.getCollection('collection').aggregate( [ {$match:{search_description:{$regex: "ab", "$options": "i"}}} ,{$match:{search_description:{$not:{$regex: "dc", "$options": "i"}}}} ] ) 以上查询结果“errms

我需要在一个条件为“ab not dc”的字段上进行正则表达式基搜索。下面是查询结果错误。建议使用一个适当的查询

db.getCollection('collection').aggregate(
[
{$match:{search_description:{$regex: "ab", "$options": "i"}}}
,{$match:{search_description:{$not:{$regex: "dc", "$options": "i"}}}}
]
)

以上查询结果“errmsg”:“错误查询:BadValue$not不能有正则表达式”错误消息

由于MongoDB支持负前瞻,您可以使用

db.getCollection('collection').aggregate(
    [
        {$match:{search_description:{$regex: "^(?!.*db).*ab.*$", "$options": "i"}}}
    ]
)    

使用这里的答案来开发一个正则表达式,以包含否定的任何反馈?根据我的要求,它对我来说是可行的,只是做了一些小的更改。谢谢