{
"source": "Chennai",
"destination": "Kolkata",
"flights": [
{
"flightId": "E6-2145",
"seatsAvailable": 10,
"fare": [
{
"travelClass": "Economy",
"baseFare": 3588
},
{
"travelClass": "Business",
"baseFare": 9999
}
]
}
]
}
I want to update the basefare of Economy class to 3800 if it is less than 3800.
I tried:
db.Flights.aggregate({
$unwind: "$flights"
},
{
$match: {
"flights.fare": {
$elemMatch: {
travelClass: "Economy",
baseFare: {
$lt: 3800
}
}
}
}
},
{
$set: {
"flights.fare.basefare": 3800
}
})
But it is updating both basefares of the flight i.e Economy as well as Business to 3800.
Please help me to solve this.