I have a collection whose documents look like this
{'_id': ObjectId('5d7f4aa4d2394d86aacbfbe0'),
'aeroplanes': [{'_id': ObjectId('5d7f4aa4d2394d86aacbfbd8'),
'capacity': 1442,
'flights': [{'_id': ObjectId('5d7f4aa4d2394d86aacbfbd7'),
'arrival_time': datetime.datetime(2010, 10, 8, 3, 26, 50),
'departure_time': datetime.datetime(1988, 6, 29, 14, 10, 52),
'gate_number': 6,
'seats': [{'_id': ObjectId('5d7f4aa4d2394d86aacbfbd6'),
'price': 1779,
'ticket': None,
'type': 'A'}]}],
I want to select all the seats with None (null) type. The output I want is like:
'seats': [
{'_id': ObjectId('5d7f4aa4d2394d86aacbfbd6'),
'price': 1779,
'ticket': None,
'type': 'A'},
{'_id': ObjectId('5d7f4aa4d2394566acfgbgt'),
'price': 3546,
'ticket': None,
'type': 'A'}
]
I tried to follow this answer and wrote this:
airline_col.aggregate([
{"$match": {'aeroplanes.flights.seats.ticket': None}},
{"$project": {
"seats" : { "$filter" : {
"input": '$aeroplanes.flights.seats',
"as": 'seat',
"cond": {"$eq": ['$$seat.ticket', None]}
}}
}}
])
But it is just returning empty arrays. What will be the correct query?
Mongo playground query link: https://mongoplayground.net/p/Wl2l4IdJLT2