title: Conditional $sum in MongoDB
body: <p>My collection in mongodb is similar to the following table in SQL:</p>
  
  <p>Sentiments(Company,Sentiment)</p>
  
  <p>Now, I need to execute a query like this:</p>
  
  <pre><code>SELECT
    Company, 
    SUM(CASE WHEN Sentiment &gt;0 THEN Sentiment ELSE 0 END) AS SumPosSenti, 
    SUM(CASE WHEN Sentiment &lt;0 THEN Sentiment ELSE 0 END) AS SumNegSenti
  FROM Sentiments
  GROUP BY Company
  </code></pre>
  
  <p>What should I do to write this query in Mongo? I am stuck at the following query:</p>
  
  <pre><code>db.Sentiments.aggregate(
  { $project: {_id:0, Company:1, Sentiment: 1} },
  { $group: {_id: "$Company", SumPosSenti: {$sum: ? }, SumNegSenti: {$sum: ? } } }
  );
  </code></pre>