0

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

1

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.