我正在尝试查询我想要检索查询数据库中字段的项目。 我需要检查一下如下(例子):
检索文本字段包含“足球”或“篮球”的书籍:
我想要的项目只在上面的人口中:
包含'1989'
和
排除'欧洲'
有什么想法吗?我现在正在计算,但它不起作用:
//search words
foreach ($cardSearch as $value) {
$regexSearch[]['text'] = new MongoRegex("/" . $value . "/");
}
//words included
foreach ($cardInclu as $value) {
$regexInclu[]['text'] = new MongoRegex("/" . $value . "/");
}
//words excluded
foreach ($cardExlu as $value) {
$regexExclu[]['text'] = new MongoRegex("/" . $value . "/");
}
$arr['$and'] = $regexInclu;
$arr['$ne'] = $regexExclu;
array_push($regexSearch, $arr);
$i = $mongoCollection->count(array('$or' => $regexSearch));
或
$i = $mongoCollection->count(array('$or' => $regexSearch,
'$and' => $regexInclu, '$ne' => $regexExclu));
谢谢!