I am using jenssegers/laravel-mongodb
I was wondering if I can do this with mongodb aggregate. I have a dataset of
And I am trying to achieve this kind of result or anything close that I can loop into
What I have right now is this:
$collegeGender = FormData::raw( function ( $collection ) {
return $collection->aggregate([
['$sortByCount' => [
'$mergeObjects' =>[
'$details.college',
'$details.gender'
]
]]
]);
});
But it is displaying an error:
$mergeObjects requires object inputs, but input "M" is of type string
Here is a sample of my collection data
{
'_id': '5d5d77de54f57118ac003b46',
'details': {
'age' : 'M',
'college' : 'College 1',
}
}
I also don't know if I am using the aggregate function correctly :)