【问题标题】:How to concat "$" special character with another field in Mongodb?如何将“$”特殊字符与 Mongodb 中的另一个字段连接起来?
【发布时间】:2019-11-08 00:30:42
【问题描述】:

我有聚合管道,在 $project 结束时,我需要发送美元金额。我需要作为“$”和金额字段连接的字符串发送。我无法使用 concat,因为“$”是 Mongodb 中的特殊字符。希望我能在这里找到答案。

以下 mongo 功能不起作用。

"$concat": [ “$”, { "$toString": "$Amount" } ]

【问题讨论】:

    标签: mongodb aggregation


    【解决方案1】:

    使用 $literal

    db.coll.aggregate([
      { $addFields : { newAmount: { $concat: [ { $literal: "$"}, { $toString: "$Amount" } ] }} }
    ])
    

    【讨论】:

    • 我怎么会想念文字。非常感谢
    猜你喜欢
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    相关资源
    最近更新 更多