你应该与
$concat
和
$toString
字符串插值的运算符。
db.collection.aggregate([
{
$project: {
"_id": 1,
"credit": "$credit.credit",
"fromAdmin": 1,
"type": 1,
"description": {
"$cond": {
"if": {
"$eq": [
"$fromAdmin",
true
]
},
"then": {
$concat: [
"Admin Credit of ",
{
$toString: "$credit.credit"
},
" Credits"
]
},
"else": {
"$cond": {
"if": {
"$eq": [
"$type",
"credit"
]
},
"then": {
$concat: [
"Purchase of ",
{
$toString: "$credit.credit"
},
" Credits"
]
},
"else": "Subscription Payment"
}
}
}
}
}
}
])
Demo @ Mongo Playground