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.
$query->select([])Why You set to select empty array?$query->createCommand()->rawSqlprints out.