在聚合中我有一个group
- 子句:
{ $group: {
_id: { town_id: "$_id.town" },
houses_data: { $push:
{ house_id: "$_id.house_id",
price: {
$divide: ["$sum", "$total"]
}
}
}
}
}
就像这样可以正常工作
但后来我尝试在description
中添加一个额外的字段houses_data
:
{ house_id: "$_id.house_id",
price: {
$divide: ["$sum", "$total"]
},
description: "thats a house"
}
现在我收到错误:
FieldPath '2' doesn't start with $"
但是描述不是字段
我想将Description添加为静态字符串值。
因此,在每个house_data
- 数组中,应该有相同的描述。
输出应如下所示:
{town_id: 13, houses_data: [
{house_id: 5, price: 32, description: "thats a house"},
{house_id: 2, price: 12, description: "thats a house"}
]
}
我错了什么?谢谢!