I am using mongodb with Laravel. I also using jenssegers/laravel-mongodb for performing database activity. I have one collection containing data of the user where the path of his picture is stored with the tags given by him. Somewhat similar to Instagram. Now I want to perform tag wise count on the data i.e. for every tag, how many records are there. Below is the structure of the collection named user_contents:
{
"_id": ObjectId("5a6f41fbf4f1f331b4006d7d"),
"user_id": "1",
"file_name": "rBrnbxjJXckR1CnvljZ4eZiXFWFWBobJiguUbHzd.jpeg",
"tags": ["blue", "girl"],
"created_at": ISODate("2018-01-29T15:47:06Z"),
"updated_at": ISODate("2018-01-29T15:47:06Z")
}
I am runnig the below query to get the desired data which works perfectly in a mongo client
db.user_contents.aggregate([{
"$project": {
"tags": 1
}
}, {
"$unwind": "$tags"
}, {
"$group": {
"_id": "$tags",
"count": {
"$sum": 1
}
}
}]);
But I don't know how to write this query using jenssegers. More specifically, I am not getting an option to execute unwind. It would be great if someone can help me with this,
Version info:
Laravel: 5.5.32
MongoDB: db version v3.6.2
php: 7.1.10
Thank you.