MongoDB按teamExternalId分组调整结果格式需求
MongoDB查询结果按teamExternalId分组
聚合查询命令
使用MongoDB的$group聚合操作可实现按teamExternalId分组,并将对应文档存入insight数组:
db.collection.aggregate([ { $group: { _id: "$teamExternalId", insight: { $push: "$$ROOT" } } }, { $project: { _id: 0, teamExternalId: "$_id", insight: 1 } } ])
分组后结果
执行上述聚合命令后,将得到如下格式的结果:
{ "teamExternalId": "b663fa97-22fa-44b9-b845-22a57d408550", "insight": [ { "_id": "89787517-0085-3a0a-7232-1105457d6075", "totalStoriesPlanned": 2, "storiesWithDependencies": 0, "plannedVelocity": null, "actualVelocity": 0, "businessValue": 0, "sprintType": "Dev", "storyData": [], "teamExternalId": "b663fa97-22fa-44b9-b845-22a57d408550" }, { "_id": "12347517-0085-3a0a-7232-1105457d6075", "totalStoriesPlanned": 2, "storiesWithDependencies": 0, "plannedVelocity": null, "actualVelocity": 0, "businessValue": 0, "sprintType": "Dev", "storyData": [], "teamExternalId": "b663fa97-22fa-44b9-b845-22a57d408550" } ] }
内容的提问来源于stack exchange,提问作者Tasneem Desai
相关产品推荐
相关产品推荐

