说我有看起来像这样的条目:
我想将priority“估计”列表中每个项目的字段增加1。
我可以这样估算:
var estimates = firebase.child('Estimates');
Run Code Online (Sandbox Code Playgroud)
之后,我如何将每个“估计”优先级自动递增1?
当我从 API 创建新文档时,我想提交(或原子更新)属于根项目文档的统计信息集合:
const increment = firebase.firestore.FieldValue.increment(1)
let aggregation: LooseObject = {
totalProjects: increment,
tags: [],
categories: [],
}
const project = fakeProject() // some debug func to return a dummy project object
const projectRef = db.collection('projects').doc()
const projectStatsRef = db.collection('projects').doc('--stats--')
project.categories.forEach((category: string) => {
aggregation.categories[category] = increment
})
project.tags.forEach((tag: string) => {
aggregation.tags[tag] = increment
})
console.log(aggregation)
const batch = db.batch()
batch.set(projectRef, project)
batch.set(projectStatsRef, aggregation, {
merge: true,
})
batch.commit()
Run Code Online (Sandbox Code Playgroud)
当我检查控制台时,我得到了聚合文档的以下转储(这是我希望在所附屏幕截图中看到的数据的形状):
{
totalProjects: NumericIncrementTransform { operand: 1 },
tags: …Run Code Online (Sandbox Code Playgroud)