MongoDB 聚合中的转换字段
Transform field in MongoDB aggregate
我通过聚合对 mongodb 进行了一些查询,我可以获得我想要的结果并将其发送给客户。
在此之后我需要合并文件名和文件 url.
我的成绩
{
"_id" : "1", "name" : "x", "image" : "y.jpg"
}
但我想像这样编辑结果
{
"_id" : "1", "name" : "x", "image" : "http:/x.com/y.jpg"
}
我可以在循环聚合后编辑结果。但是总计可以给我吗?
演示 - https://mongoplayground.net/p/nWv7d2Ld5sy
db.collection.aggregate([
{
$set: {
image: {
$concat: [ "http://", "$name", ".com/", "$image" ] // combine to form the output
}
}
}
])
我通过聚合对 mongodb 进行了一些查询,我可以获得我想要的结果并将其发送给客户。 在此之后我需要合并文件名和文件 url.
我的成绩
{
"_id" : "1", "name" : "x", "image" : "y.jpg"
}
但我想像这样编辑结果
{
"_id" : "1", "name" : "x", "image" : "http:/x.com/y.jpg"
}
我可以在循环聚合后编辑结果。但是总计可以给我吗?
演示 - https://mongoplayground.net/p/nWv7d2Ld5sy
db.collection.aggregate([
{
$set: {
image: {
$concat: [ "http://", "$name", ".com/", "$image" ] // combine to form the output
}
}
}
])