Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get the root ref in Cloud Functions for Firebase

There is another way for get the root ref?

exports.orderUser = functions.database.ref('/orders/{shopId}/{orderId}').onWrite(event => {
    var eventSnapshot = event.data;
    // ...
    var rootRef = eventSnapshot.ref.parent.parent.parent; <== this line
    var userRef = rootRef.child(`/users/${user}/orders`);
});
like image 270
SaroVin Avatar asked Jan 05 '23 07:01

SaroVin


1 Answers

eventSnapshot.ref.root will give you the root reference.

like image 135
James Daniels Avatar answered Jan 14 '23 12:01

James Daniels