1 回答
- 最新
- 投票最多
- 评论最多
0
DocumentDB does support $reduce. for
rs0:PRIMARY> db.testc.find()
{ "_id" : "3_0", "values" : [ "Test1", "Test2" ] }
rs0:PRIMARY> db.testc.aggregate([ { "$addFields": { "values": { "$reduce": { "input": "$values", "initialValue": "", "in": { "$cond": { "if": { "$eq": [ { "$indexOfArray": [ "$values", "$$this" ] }, 0 ] }, "then": { "$concat": [ "$$value", "$$this" ] }, "else": { "$concat": [ "$$value", "_", "$$this" ] } } } } } }} ])
{ "_id" : "3_0", "values" : "Test1_Test2" }
rs0:PRIMARY> db.version()
4.0.0
已回答 2 年前