I have the collection BookingDetails with below record:
{
"code" : "TICKET1234",
"orderDetails" : [
{
"cost": 150.0,
"movieName": "avengers"
}
]
},
{
"code" : "TICKET1235",
"orderDetails" : [
]
}
Need to check if the orderDetails.MovieName exists or not on the projection layer. I tried below query, it is not helpful.
db.BookingDetails.aggregate([
{
$project: {
OrderExists: {
$cond: [
{ $ne: ["$orderDetails.0.movieName", null] },
1, 0
]
}
}
}
])
I can't use $exists inside $cond. I tried $ifNull as well. Need your thoughts on this.