I need results from my collection where the field user_id (a string) does not have abc
or def
anywhere in it. Here's what I tried:
$regex_array = array("/abc/", "/def/");
$cursor = $colection->find(array('user_id'=> array('$nin'=> $regex_array)));
$cursor = $colection->find(array('user_id'=> array('$regex'=> array('$nin'=> $regex_array))));
When I iterate over the cursor, I'm finding that it is still allowing abc
and def
as substrings in the results.
Any other way to express the said query?
Instead of testing multiple regexes, you can combine several regexes into one:
/regex1/ or /regex2/
translates to
/(?:regex1)|(?:regex2)/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.