I have this collection
db.Tratte.insert(
{
"TransportID":["9901","9903"],
"StopsBy":[
{"Station":"Roma Termini",
"StopsAt":ISODate("2016-01-01T09:05:00Z"),
"LeavesAt":ISODate("2016-01-01T09:25:00Z")},
{"Station":"Napoli Centrale",
"StopsAt":ISODate("2016-01-01T10:37:00Z"),
"LeavesAt":ISODate("2016-01-01T10:52:00Z")},
{"Station":"Salerno",
"StopsAt":ISODate("2016-01-01T11:35:00Z")}]
})
and I want to extract the date (and only the date) when the train leaves "Roma Termini".
I tried the following query, but in this way I obtain all the information.
db.Tratte.find({"TransportID":"9901"},
{ StopsBy:
{
$elemMatch: { "Station": "Roma Termini" }
}
}
)
How can I extract only the "LeavesAt" field related to "Roma Termini"? Thanks