Anda dapat mencoba kueri di bawah ini menggunakan $max
operator agregasi.
db.collection.aggregate([
{ "$project": {
"name": 1,
"startDate": { "$min": "$tasks.startDate" },
"endDate": { "$max": "$tasks.endDate" }
}}
])
[
{
"_id": ObjectId("5a934e000102030405000000"),
"endDate": ISODate("2018-09-29T10:02:49.403Z"),
"name": "p1",
"startDate": ISODate("2018-09-24T10:02:49.403Z")
}
]