CLOVIS
03/03/2025, 8:00 AMusers().aggregate()
.project {
include(User::name)
User::bestPassingGrades set User::grades
.filter { it gt of(50) }
.map { it / Grade::value }
.sortedDescending()
.take(of(3))
}
.sort { ascending(User::name) }
.limit(2)
Or BSON?
[
{
"$project": {
"name": 1,
"bestPassingGrades": {
"$firstN": {
"input": {
"$sortArray": {
"input": {
"$map": {
"input": {
"$filter": {
"input": "$grades",
"as": "this",
"cond": {"$gt": ["$$this", {"$literal": 50}]}
}
},
"as": "this",
"in": {"$getField": {"input": "$$this", "field": "value"}}
}
},
"sortBy": -1
}
},
"n": {"$literal": 3}
}
}
}
},
{"$sort": {"name": 1}},
{"$limit": 2}
]
If you're in Bordeaux, France, I'm giving a talk on the KtMongo project, its current limitations, and how it can be adopted in a KMongo project, in two weeks. You can sign up for free here.
If you use aggregation pipelines, I am searching for users who use temporary variables within their pipelines to discuss how KtMongo could help. Please get in touch.
https://opensavvy.gitlab.io/ktmongo/docs/news/2025/03/01/v0.12.0.html