简体   繁体   中英

How can I fetch data from inside a node which the database.ref is listening to in my Firebase real-time database using cloud functions?

Below is a part of the function that I'm using to fetch data.

functions.database.ref(/path/{pushId}')
    .onCreate((snapshot,context)=>{
        const original = snapshot.val();

Below is the structure of my DB.

"path":{
    "$pushId":{
            "products": {
                         "0" : {
                               "cabinet": "cabinet1"
                               },
                         "1" : {
                               "cabinet": "cabinet2"
                               }
                         }
              }
}

How can I fetch the value of each cab.nets stored inside products node insdie the path/{pushId} that my function is listening to?

Try this:

functions.database.ref(/path/{pushId}')
    .onCreate((snapshot,context)=>{
        const original = snapshot.val();

        Object.keys(original).forEach(key => {
          const product = original[key];
          console.log(product.cabinet);
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM