I am trying to execute MongoDB aggregation command with lookup stage, but the command does not seem to be working:
// col_1
{
"_id" : 1,
"sever_id" : 1,
"question" : "What is option",
"status" : "active",
"no_of_options" : "2"
}
// col_2
{
"_id" : 1,
"col_1_id" : 1,
"option" : "option 1",
"votes" : 0
}
{
"_id" : 2,
"col_1_id" : 1,
"option" : "option 2",
"votes" : 0
}
$connection = get_mongodb_connection();
$command = new MongoDB\Driver\Command([
'aggregate' => 'col_1',
'pipeline' => [
['$match' => ['sever_id' => 1]],
['$lookup' => [
"localField" => '_id',
"from" => 'col_2',
"foreignField" => 'col_1_id',
"as" => 'options',
]],
],
'cursor' => new stdClass,
]);
$cursor = $connection->executeCommand('testdb', $command);
this command is returning blank array in cursor.
It is pretty simple but not working. What am I doing wrong in this case ?