I want to retrieve documents from mongoDb by using MongoClient for parent_id is only first of same and parent_id is null.Only one aggregation.
$search[] = [
'$group' => [
'_id' => '$parent_id',
'doc' => ['$first' => '$$ROOT']
]
];
$search[] = [
'$replaceRoot' => ['newRoot' => '$doc']
];
app('mongo')->todo->Product->aggregate(array_filter($search));