1

I am trying to make a query that compares with array field in table (vendor). I create following query using Yii2 but it returns empty records.

    $id = Yii::$app->getRequest()->getQueryParam('catid');

    $query = new Query;

    $query->select([])
        ->from('vendor')
        ->where(['category' => $id]);

     $rows = $query->all();

    return json_encode($rows);

I used mongodb. Here is my table vendor. This is a record from the vendor table.

{
    "_id" : ObjectId("5583f354d88488081b8b4567"),
"address" : "Parle point",
"category" : [ 
    "55a4db79d884888310a7c07e", 
    "55a4ca94d88488320fa7c07e", 
    "55a4e2bfd884888310a7c080"
],
"city" : "Surat",
"country" : "India",
"created_at" : "",
"description" : "Cat Description",
"email" : "[email protected]",
"firstName" : "vendor1",
"is_visible" : "Visible",
"lastName" : "test",
"logo" : "Image",
"phoneNumber" : "686986979",
"pincode" : "395007",
"state" : "Gujarat",
"updated_at" : NumberLong(1436942895),
"url" : "test,com"
}

Why is my select query not returning any records? Remember comparison field has an array datatype.

3
  • $query->select([]) Why You set to select empty array? Commented Aug 11, 2015 at 9:13
  • it means i want all the columns of vendor table. Commented Aug 11, 2015 at 9:54
  • You should post what $query->createCommand()->rawSql prints out. Commented Aug 13, 2015 at 11:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.