如何从Google云端扫描器触发云端功能
问题描述:
如何发送每次将新文件添加到Android Studio的Firestore时生成的DocumentReference.getId()
到在Firestore上执行写入/创建操作时触发的云端函数。 我尝试以下如何从Google云端扫描器触发云端功能
'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的自动识别从Android工作室通过的文件编号为云功能
答
你想在你的函数中使用通配符:
exports.helloUser = functions.firestore
.document('BankInform/{transactionId}')
.onUpdate(event =>{
var transactionId = event.params.transactionId
console.log(transactionId); // Moj2HBrxepX5R7FonvrO
});
如您所见,您应该能够使用event.params
从函数中获取适当的文档名称。
你还尝试过什么吗?如果不是,我建议从[Firestore for Cloud Functions的触发器文档](https://firebase.google.com/docs/functions/firestore-events)开始。如果您遇到/遇到困难,请分享[重现您卡住的最小代码](http://*.com/help/mcve)。 –