在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java  數(shù)據(jù)庫(kù)/ spring boot怎么使用mongodb進(jìn)行ifelse操作

spring boot怎么使用mongodb進(jìn)行ifelse操作

數(shù)據(jù)存放了一個(gè)字段type(當(dāng)作枚舉),查詢的時(shí)候,需要通過(guò)使用ifelse或者switch另作處理,比如1就*5,2就轉(zhuǎn)化為正常。我用mongodb語(yǔ)句已經(jīng)實(shí)現(xiàn),但是怎么在springboot 框架中處理呢?sql語(yǔ)句如下:

ifelse:

db.getCollection('Historys').aggregate(
    [
    {
        $project:{
            "count":{
                $cond:{
                        if:{$eq:["$type",1]},then:1*8,else:{
                        $cond:{if:{$eq:["$type",2]},then:2,else:{
                            $cond:[{$eq:["$type",3]},5,0]
                            }}
                        }
                    }
                }
            }
        }
    ]
    )

switch:

db.getCollection('Historys').aggregate([{
    $project:{"type":1,"count":
        {$switch:{
            branches:[
            {case:{$eq:["$type",1]},then:1*9},
            {case:{$eq:["$type",2]},then:"2"},
            {case:{$eq:["$type",3]},then:"3"}
            ],
            default:0
            }}
        }
    }])
回答
編輯回答
來(lái)守候

把你的語(yǔ)句拼成mongodb的Document@@

2017年12月19日 12:47