Suppose after the $facet stage I have a result including two arrays: roomInfo and hotelInfo.
Which looks like this:
{
"roomInfo": [
{
_id: 'ab1',
booked: 3
},
{
_id: 'ab2',
booked: 1
}
],
"hotelInfo": [
{
name: 'Radison Blue',
roomDetails: [
{
_id: 'ab1',
roomCount: 5
},
{
_id: 'xy1',
roomCount: 5
}
]
},
{
name: 'Intercontinental',
roomDetails: [
{
_id: 'ab2',
roomCount: 5
}
]
}
]
};
Expected Result
I want an output like this:
[
{
name: 'Radison Blue',
roomDetails: [
{
_id: 'ab1',
roomCount: 5,
booked: 3
},
{
_id: 'xy1',
roomCount: 5,
booked: 0
}
]
},
{
name: 'Intercontinental',
roomDetails: [
{
_id: 'ab2',
roomCount: 5,
booked: 1
}
]
}
];
Basically, adding the booked property from roomInfo into the hotelInfo's roomDetails field after matching their ids.
- Additionally, after getting the above output result I want to exclude those hotels on which all the rooms(not for a single room) have the value of fields roomCount and booked equal. I want to do this inside the aggregation pipeline stage as I will have to deal with $skip and $limit later on.
How to achieve these use cases?
Thanks!