如何从 Google cloud firestore 触发 Cloud Functions

How to trigger Cloud Functions from Google cloud firestore

如何将每次将新文档添加到 firestore 时生成的 DocumentReference.getId() 从 Android Studio 发送到在 Firestore 上有 write/create 操作时触发的云功能. 我尝试关注

'use strict';
const  https = require( 'firebase-functions');
const functions = require('firebase-functions');
const Firestore = require('@google-cloud/firestore');
const firestore = new Firestore();
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.helloUser = functions.firestore
    .document('BankInform/Moj2HBrxepX5R7FonvrO')
    .onUpdate(event =>{
    var newValue = event.data.data();
return event.data.ref.update({
    "status": "Success"
    });

    });

但我必须提供 document.How 的 autoid 才能将文档 ID 从 android studio 传递到云函数

您想在函数中使用通配符:

exports.helloUser = functions.firestore
    .document('BankInform/{transactionId}')
    .onUpdate(event =>{
        var transactionId = event.params.transactionId
        console.log(transactionId);  // Moj2HBrxepX5R7FonvrO
    });

如您所见,您应该能够使用 event.params 从函数中获取适当的文档名称。