Mongodb concat int and string

前端 未结 3 2168
清酒与你
清酒与你 2020-12-03 17:14

I\'m trying to project FileName and FileSize for all my files in my collection with a size of 50 mb and greater, but I cannot concat a the type FileSize as it has a type of

3条回答
  •  [愿得一人]
    2020-12-03 17:43

    It is possible now in MongoDB v4.0 using $toString operator which converts a value to a string:

    db.col.aggregate([
        {
            $project: {
                FileSize: { $concat: [ { $toString: "$FileSize" }, " MB" ] }
            }
        }
    ])
    

提交回复
热议问题