如何从Google云端防火墙触发云功能

时间:2017-10-16 08:40:27

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

如何将每次将新文档从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"
    });

    });

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

1 个答案:

答案 0 :(得分:2)

您希望在函数中使用通配符:

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

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

相关问题