im-learning
im-learning

Reputation: 117

Yii2 convert MongoDB query a Yii query

I have use this query command in terminal on mongo and it's working with scor sort

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

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

this query is working on mongo on my terminal I did :

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

The query is working good on mongo on terminal I copy it from : https://docs.mongodb.com/manual/reference/operator/query/text/

The error I get :

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

Upvotes: 0

Views: 198

Answers (1)

Alex
Alex

Reputation: 2122

I've not used mongodb with Yii myself but I think you've gone one level too deep with the array.

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

Upvotes: 2

Related Questions