在具有条件的字段中,如何替换句子中的值?我试过以下几种方法,但不起作用.
{
$project: {
"_id":1,
"credit":"$credit.credit",
"fromAdmin":1,
"type":1,
"description": {
"$cond": {
"if": { "$eq": [ "$fromAdmin", true ] },
"then": 'Admin Credit of $credit.credit Credits',
"else": {
"$cond": {
"if": { "$eq": ["$type","credit"]},
"then": "Purchase of $credit.credit Credits",
"else": 'Subscription Payment'
}
}
}
}
}
},
我得到的结果是:"Admin Credit of$Credit it.Credit Credit"
预期结果:"管理学分10学分"