Grouping and Sum with Conditions
<p>I use mongoTemplate to query my mongodb database, and I want to do some counting in my collections. I want to group by id and include counting with conditions. I used this query in mongoshell </p>

<pre><code>db.scenarios.aggregate([
    { $match: { bid: "build_1481711758" } },
    {
        $group: {
            _id: "$bid",
            nb: { $sum: 1 },
            nbS: {
                "$sum": {
                    "$cond": [
                        { "$eq": ["$scst",  true ] },  
                        1, 0 
                    ]
                }
            },
            nbE: {
                "$sum": {
                    "$cond": [
                        { "$eq": ["$scst",  false ] },  
                        1, 0 
                    ]
                }
            }
        }
    }
])
</code></pre>

<p>and it returns what I want, but I dont know how to convert it to java mongotemplate.</p>

<p>Please help :)</p>