[
{
"$match": {
"userId": "user_1"
}
},
{
"$lookup": {
"from": "Events",
"localField": "eventId",
"foreignField": "_id",
"as": "eventDetails"
}
},
{
"$addFields": {
"eventName": { "$ifNull": [{ "$arrayElemAt": ["$eventDetails.name", 0] }, "Unknown"] },
"date": { "$ifNull": [{ "$arrayElemAt": ["$eventDetails.date", 0] }, "Unknown"] },
"location": { "$ifNull": [{ "$arrayElemAt": ["$eventDetails.location", 0] }, "Unknown"] }
}
},
{
"$group": {
"_id": "$eventId",
"eventName": { "$first": "$eventName" },
"date": { "$first": "$date" },
"location": { "$first": "$location" },
"tickets": { "$addToSet": "$_id" },
"count": { "$sum": 1 }
}
}
]
I am not sure how to convert this to Java code. Can someone help me with it?
The code conversion provided by MongoDB Atlas doesn't seem to be reliable.
I want to convert this to Java Code using Aggregations.