【发布时间】:2021-10-31 05:32:40
【问题描述】:
我有一个文档,其中有两个字段;
- 类别
- 以微毫秒为单位的持续时间
Category 可以有多个值,例如 category1、category2 等。
我想计算类别 == category1 的所有文档的持续时间总和。请帮忙查询。
import * as admin from 'firebase-admin'
import * as functions from 'firebase-functions'
admin.initializeApp()
export const updateCharts =
functions.firestore.document('users/{UserId}/count/{uid}')
.onWrite(async(change, _) => await updateStats(change))
async function updateStats (change:
functions.Change<functions.firestore.DocumentSnapshot>){
const chartRating = change.after.ref.parent
let title = (await chartRating.where('Title', '==', 'Game').get()).size;
//duration
const restaurantRef = chartRating.parent!
console.log('{restaurantRef.path} now has ${Title}')
await restaurantRef.update({
Title: Title,
})
【问题讨论】:
标签: node.js typescript firebase google-cloud-firestore google-cloud-functions