数据格式:
{
"_id": ObjectId("5cc83985ef921e27e17e1b6e"),
"domainId": NumberLong("10"),
"shop": DBRef("shop_shop", ObjectId("5cc83985ef921e27e17e1b6a")),
"simpleShop": {
"shopId": ObjectId("5cc83985ef921e27e17e1b6a"),
"shopCode": [
"10-01-10-02-01-006"
],
"shopType": "PUBLIC_SHOP",
"shopNature": "RENT",
"shopLocations": [
{
"marketId": "5c8f7db0f45a923e561051be",
"market": "测试路1号",
"buildingId": "5cc8133997bcec029206ae86",
"building": "AD天桥",
"floor": NumberInt("2"),
"road": "AD天桥",
"number": "002"
}
],
"area": NumberDecimal("25.5"),
"coveredArea": NumberDecimal("0"),
"businessScope": [
"a-b-c"
],
"brands": [
"xxx"
],
"block": "aaa",
"level": NumberDecimal("0"),
"tenants": [
{
"_id": ObjectId("5cc8133a008ec91198f192c5"),
"customerType": "PERSONAL",
"name": "周奇",
"mobile": "13588888888"
}
]
},
"businessUsers": [
{
"_id": ObjectId("5cc8133a008ec91198f192c5"),
"customerType": "PERSONAL",
"name": "周奇",
"mobile": "13588888888"
}
]
}
想要输出的数据格式:
{
"_id": ObjectId("5cc83985ef921e27e17e1b6e"),
"shopLocations": [
"测试路1号AD天桥2AD天桥002"
],
"tenants": [
{
"name": "周奇",
"mobile": "13588888888"
}
],
"businessUsers": [
{
"name": "周奇",
"mobile": "13588888888"
}
]
}
代码:
db.shop_shop_business.aggregate({
$project: {
_id: 1,
shopLocations: {
$map: {
input: "$simpleShop.shopLocations",
as: "s",
in: {
$concat: ["$$s.market", "$$s.building", {
$toString: "$$s.floor"
}, "$$s.road", "$$s.number"]
}
}
},
tenants: {
$map: {
input: "$simpleShop.tenants",
as: "s",
in: {
name: "$$s.name",
mobile: "$$s.mobile"
}
}
},
businessUsers: {
$map: {
input: "$businessUsers",
as: "s",
in: {
name: "$$s.name",
mobile: "$$s.mobile"
}
}
}
}
});