首页 > 解决方案 > 云存储功能不是从应用程序(flutter)触发,而是在直接在firestore中进行更改时触发

问题描述

我有一个文档,其中有两个字段;

类别和持续时间(以微毫秒为单位)。类别可以有多个值,如类别 1、类别 2 等。

我想计算类别 == category1 的所有文档的持续时间总和。我对这里的代码做了一些更改,它现在可以工作了。但是我有一个奇怪的问题,当我通过应用程序界面进行更改时,更新没有被触发。应用程序可以正常创建。但是当我直接在firestore中进行更改时,更新工作正常。请帮忙。

import * as admin from 'firebase-admin'
import * as functions from 'firebase-functions'


admin.initializeApp()

export const updateData = 
functions.firestore.document('users/{UserId}/count/{uid}')
.onWrite(async(change, _) => await dataUpdates(change))

async function dataUpdates (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,
    
    })

标签: google-cloud-firestoregoogle-cloud-functions

解决方案


推荐阅读