在MongoDB
中,我知道在sql
中使用“ find”可以类似于“ like”,但是当多个和和为“ likes”时,我无法找到如何在“ aggregate”中使用它的答案用法类似于以下代码。可以使用“ $ match”和“ regex”,但不适用于不同总和的匹配条件,如下面的代码。
如何将下面的MySQL代码转换为MongoDB
?
select login,
sum(case when comment like '%Deposit%' and comment not like 'Deposit-bonus%' and comment not like 'Deposit-with%' and cmd = 6 then profit else 0 end) as deposit
,
sum(case when comment like '%with%' and cmd = 6 then profit else 0 end) as withdrawal
from trades
group by login