Consulting a subdocument in aggregatr

Hello, I’ve been having trouble with an aggregate exercise. Let’s suppose that I have a database structured like thus:

collection parking
{
zone: ‘A’
num: 1
cars stationed: [{car registration: “1234ABC”, date_entrance: DATE, date_leave: DATE}]
}

I would like to show the car registration if I can find a car that has been stationed in that parking in a specific date, or say “no car stationed” if there is none, is it possible?

Hi @Adri and welcome to the MongoDB Community forum!!

To understand the requirements better, could you help me with some sample data from the collection. Also please help me with the expected output from the aggregation query.

By then, I would recommend you going through MongoDB Aggregations to learn how are aggregations written in MongoDB.

Regards
Aasawari

No worries! I found out how to do it with a conditional $project

Thanks for sharing such insights mate.