【问题标题】:Yii2 convert MongoDB query a Yii queryYii2 将 MongoDB 查询转换为 Yii 查询
【发布时间】:2021-10-13 05:55:58
【问题描述】:

我在 mongo 的终端中使用了这个查询命令,它正在使用 scor 排序

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

【问题讨论】:

    标签: mongodb yii yii2 yii2-advanced-app yii-extensions


    【解决方案1】:

    我自己没有在 Yii 上使用过 mongodb,但我认为你对数组的了解太深了。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      • 1970-01-01
      • 2020-01-19
      • 1970-01-01
      相关资源
      最近更新 更多