How to use aggregate with ReactiveMongo
<p>So, I need to sort my collection on MongoDB by fields that are on an array of objects. </p>

<p>I have </p>

<pre><code>"columns": [{
    "kind": "FirstKind",
    "descriptor": "Description1",
    "data": "Data to be sorted"
},{
    "kind": "SecondKind",
    "descriptor": "Description2",
    "data": "Data to be sorted"
}]
</code></pre>

<p>What I want to achieve is selecting "FirstKind" <em>and</em> "Description1" or "SecondKind" <em>and</em> "Description2" and sort the collection by the field data. I found a solution to do that on MongoDB, by doing:</p>

<pre><code>db.getCollection('results').aggregate(
    [{ 
        "$match": { 
           "$and": [{
               "columns.kind": "FirstKind"
            }, {
               "columns.descriptor": "Name" 
            }] 
        } 
    },{ 
        "$sort": { 
           "columns.data": -1 
         } 
    },{ 
        "$limit": 20 
    }]
)
</code></pre>

<p>My problem now is how to translate that to ReactiveMongo on Scala. I've been trying to understand this documentation: <a href="http://reactivemongo.org/releases/0.11/documentation/advanced-topics/aggregation.html" rel="nofollow">http://reactivemongo.org/releases/0.11/documentation/advanced-topics/aggregation.html</a> but I'm really confused about it. Has anyone ever used aggregate with ReactiveMongo on Scala? Thanks!</p>