So, I need to sort my collection on MongoDB by fields that are on an array of objects.
I have
"columns": [{
"kind": "FirstKind",
"descriptor": "Description1",
"data": "Data to be sorted"
},{
"kind": "SecondKind",
"descriptor": "Description2",
"data": "Data to be sorted"
}]
What I want to achieve is selecting "FirstKind" and "Description1" or "SecondKind" and "Description2" and sort the collection by the field data. I found a solution to do that on MongoDB, by doing:
db.getCollection('results').aggregate(
[{
"$match": {
"$and": [{
"columns.kind": "FirstKind"
}, {
"columns.descriptor": "Name"
}]
}
},{
"$sort": {
"columns.data": -1
}
},{
"$limit": 20
}]
)
My problem now is how to translate that to ReactiveMongo on Scala. I've been trying to understand this documentation: http://reactivemongo.org/releases/0.11/documentation/advanced-topics/aggregation.html but I'm really confused about it. Has anyone ever used aggregate with ReactiveMongo on Scala? Thanks!