【问题标题】:How to trigger Cloud Functions from Google cloud firestore如何从 Google Cloud Firestore 触发 Cloud Functions
【发布时间】:2018-03-27 17:30:09
【问题描述】:

如何将每次将新文档从 Android Studio 添加到 Firestore 时生成的 DocumentReference.getId() 发送到在 Firestore 上进行写入/创建操作时触发的云函数。 我试过了

'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"
    });

    });

但我必须给出文档的 autoid。如何将文档 ID 从 android studio 传递到云函数

【问题讨论】:

标签: firebase google-cloud-firestore google-cloud-functions


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 2020-02-04
    • 2018-10-16
    • 2021-11-09
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多