gpt4 book ai didi

php - MongoDB (PHP) 中的 $or-Operator

转载 作者:可可西里 更新时间:2023-11-01 10:44:33 24 4
gpt4 key购买 nike

大家好,我想通过 $or-Operator 搜索文档...一开始我插入了 3 个文件:

$aDocument = array(
'id' => 1,
'name' => 'WinZIP',
'shorttext' => 'ZIP / UNZIP Programm' );

$oCollection->insert( $aDocument );

$aDocument = array(
'id' => 2,
'name' => 'WinRar',
'shorttext' => 'ZIP / UNZIP Programm mit RAR-Unterstützung' );

$oCollection->insert( $aDocument );

$aDocument = array(
'id' => 3,
'name' => '7zip',
'shorttext' => 'ZIP / UNZIP Programm mit RAR- und 7z-Unterstützung' );

$oCollection->insert( $aDocument );

然后我正在为我的查询创建一个正则表达式:

$oSearchRegex = new MongoRegex( "/zip/i" );

现在我想在 'name' 或 'shorttext' 中搜索字符串 'zip'...应该是这样的:

$oCursor = $oCollection->find( array( '$or' => array( array( 'name' => $oSearchRegex ), array( 'shorttext' => $oSearchRegex ) ) ) );

但这行不通......当我只搜索一个索引时,它工作得很好......示例:

$oCursor = $oCollection->find( array( 'name' => $oSearchRegex ) );

有什么解决办法吗?

最佳答案

正如您所说,您拥有 1.4.4 MongoDB 版本,但 “或”运算符仅从 1.7.x 版本开始包含

关于php - MongoDB (PHP) 中的 $or-Operator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12940833/

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