【发布时间】:2019-11-08 00:30:42
【问题描述】:
我有聚合管道,在 $project 结束时,我需要发送美元金额。我需要作为“$”和金额字段连接的字符串发送。我无法使用 concat,因为“$”是 Mongodb 中的特殊字符。希望我能在这里找到答案。
以下 mongo 功能不起作用。
"$concat": [ “$”, { "$toString": "$Amount" } ]
【问题讨论】:
标签: mongodb aggregation
我有聚合管道,在 $project 结束时,我需要发送美元金额。我需要作为“$”和金额字段连接的字符串发送。我无法使用 concat,因为“$”是 Mongodb 中的特殊字符。希望我能在这里找到答案。
以下 mongo 功能不起作用。
"$concat": [ “$”, { "$toString": "$Amount" } ]
【问题讨论】:
标签: mongodb aggregation
使用 $literal
db.coll.aggregate([
{ $addFields : { newAmount: { $concat: [ { $literal: "$"}, { $toString: "$Amount" } ] }} }
])
【讨论】: