Hi, please i need help i’m finding it hard to filter my documents from mongodb atlas using php.
this is my document structure.
Initial Collection
{ _id :6257f1b36d001b68325e709e
id :2348
status :1
album_id :0
rp_id :33
lang_id :7
cat_id : Array ['01010', '42650']
mp3_thumbnail :"498.jpg"
cat_name :"men"
}
**
- Lookup method1
$ops = [ // (1)
'$lookup' => [
'from' => 'tbl_category_try', //collection to join
'let' => ["catfed" => '$cat_id'], // cat_id field coming from coll1
'pipeline' => [
['$match' => [$id => ['$in' => ['$$catfed'] ] ] ] // $id variable coming from url as argument
],
'as' => 'joinTab1',
],
];
Error: Returning all records and empty joint array joinTab1
- Lookup Method2
$ops = [ // (1)
'$lookup' => [
'from' => 'tbl_category_try',
'let' => ["catfed" => '$cat_id'],
'pipeline' => [
['$match' => ['$expr' => ['$in' => [$id, '$$catfed' ] ] ] ]
],
'as' => 'joinTab1',
],
];
Error: failed to optimize pipeline :: caused by :: Failed to optimize expression :: caused by :: $in requires an array as a second argument, found: string