I have the following schema for documents in my collection. Each document corresponds to list all the submissions made by a name.
- "_id": ObjectId
- "name": str
- "is_team": bool
- "submissions": List
- time: datetime
- score: float
Example:
{"name": "Intrinsic Nubs",
"is_team": true,
"submissions": [
{
"score": 61.77466359705439,
"time": {
"$date": {
"$numberLong": "1656009267652"
}
}
},
{
"score": 81.77466359705439,
"time": {
"$date": {
"$numberLong": "1656009267680"
}
}
}]}
I need to collect all those documents whose is_team is True and further get the name, Maximum Score and time corresponding to the maximum score.
Example:
[{"name": "Intrinsic Nubs", "MaxScore": 81.77466359705439, "time":{ "$date": {"$numberLong": "1656009267680"}}}]
2
Answers
Query
is_team=true
$project
, futher i kept all to see the changePlaymongo
Here’s another way to produce your desired output.
Try it on mongoplayground.net.