Reputation: 513
How to send the DocumentReference.getId()
that is generated every time a new document was added to firestore from Android Studio to cloud function that triggers when there is a write/create operation on Firestore.
I tried following
'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"
});
});
But I have to give the autoid of document.How to pass document id from android studio to cloud functions
Upvotes: 0
Views: 1281
Reputation: 15963
You want to use wildcards in your function:
exports.helloUser = functions.firestore
.document('BankInform/{transactionId}')
.onUpdate(event =>{
var transactionId = event.params.transactionId
console.log(transactionId); // Moj2HBrxepX5R7FonvrO
});
As you can see, you should be able to use event.params
to get the appropriate document name from the function.
Upvotes: 2