集合中的文档结构cities
是这样的
城市
{
_id: ObjectId("5e78ec62bb5b406776e92fac"),
city_name: "Mumbai",
...
...
subscriptions: [
{
_id: 1,
category: "Print Magazine",
subscribers: 183476
options: [
{
name: "Time",
subscribers: 56445
},
{
name: "The Gentlewoman",
subscribers: 9454
},
{
name: "Gourmand",
subscribers: 15564
}
...
...
]
},
{
_id: 2,
category: "RSS Feed",
subscribers: 2645873
options: [
{
name: "Finance",
subscribers: 168465
},
{
name: "Politics",
subscribers: 56945
},
{
name: "Entrepreneurship",
subscribers: 56945
},
...
...
]
}
]
}
现在当用户订阅如下
{
cityId: 5e78ec62bb5b406776e92fac
selections: [
{
categoryId: 1,
options : ["Time", "Gourmand"]
},
{
categoryId: 2,
selected: ["Politics", "Entrepreneurship"]
}
]
}
我想更新文档中的以下cities
内容
- 将“印刷杂志”的订阅者增加 1
- 将“时间”的订阅者增加 1
- 将“美食家”的订阅者增加 1
- 将“RSS Feed”的订阅者增加 1
- 将“政治”的订阅者增加 1
- 将“创业”的订阅者增加 1
因此,当一个项目被订阅时,它的订阅者计数增加 1。它所属的类别,它的订阅者计数也增加 1。
我想在单个更新查询中实现这一点。任何提示我该怎么做?
用例详情
每个用户的订阅详细信息都存储在user_subscription_details
集合中(此处未列出)。subscriptions
属性 incities
仅保存每个城市的订阅摘要。