data stores a field type (as an enumeration). When querying, it needs to be processed separately by using ifelse or switch, for example, 1 is converted to normal. I"ve implemented it with the MongoDB statement, but how do I handle it in the springboot framework? The sql statement is as follows:
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
}}
}
}])