Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore cloud functions - access variable in path

So I have this architecture in my db : test1/{test1Id}/test2/{test2Id}

I want to interact with my DB in cloud functions whenever a new one is added :

exports.test = functions.firestore
  .document('test1/{test1Id}/test2/{test2Id}')
  .onCreate(async (testsnap, context) => {
    console.log(testsnap.id);
    console.log(test1Id);
  });

but test1Id is then undefined. How can I access it ?

Thanks ahead.

like image 551
Jeremy Belolo Avatar asked Oct 20 '25 02:10

Jeremy Belolo


1 Answers

You must use

context.params.test1Id

All parameters are held under the context object

like image 107
Jonathan Avatar answered Oct 23 '25 02:10

Jonathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!