Yii2将MongoDB查询转换为Yii查询

atmip9wb  于 2022-11-09  发布在  Go
关注(0)|答案(1)|浏览(162)

我已经在mongo终端中使用了这个查询命令,它与scor sort一起工作

db.stores.createIndex( { name: "text", description: "text" } )

db.articles.find( { $text: { $search: "coffee" } } )

这个查询是在我的终端上的mongo上工作的我做了:

$collection = Yii::$app->mongodb->getCollection('mydata');
        $result = $collection->find([
            [
                '$text' => [
                    '$search' => $key,
                ]
            ]
        ]);

查询在mongo终端上运行良好,我是从以下位置复制的:https://docs.mongodb.com/manual/reference/operator/query/text/
我得到的错误:

TypeError
strtoupper(): Argument #1 ($string) must be of type string, array given
t8e9dugd

t8e9dugd1#

我自己没有用过mongodb和Yii,但是我认为你在数组上做得太深了。

$collection = Yii::$app->mongodb->getCollection('mydata');
$result = $collection->find([
  '$text' => [
    '$search' => $key,
  ]
]);

相关问题