@JoaoAlvesMarrucho Я добавил ответ

аюсь клонировать данные «оригинального» узла (как только я создаю данные) в путь, основанный на пути исходного узла.

Это моя структура данных:

root: { 
  doors: {
    111111111111: {
       MACaddress: "111111111111",
       inRoom: "-LBMH_8KHf_N9CvLqhzU", // I will need this value for the clone's path
       ins: {
          // I am creating several "key: pair"s here, something like:
          1525104151100: true,
          1525104151183: true,
       }
    }
  },
  rooms: {
    -LBMH_8KHf_N9CvLqhzU: {
      ins: {
        // I want the function to clone the same data here:
        1525104151100: true,
        1525104151183: true,
      }
    }
  }

Моя облачная функция теперь выглядит так:

exports.updateRoom = functions.database.ref('/doors/{MACaddress}/ins').onWrite((change, context) => {
    const beforeData = change.before.val(); // data before the write
    const afterData = change.after.val(); // data after the write
    const roomPushKey = change.before.ref.parent.child('/inRoom');
    console.log(roomPushKey); // this is retrieving all the info about the ref "inRoom" but not its value... 

Вопрос 1) Как я могу получить значение этого ref / узла?

Мой код продолжается, пытаясь получить значение, как это.

    roomPushKey.once('child_added').then(function(dataSnapshot) {
        let snapVal = dataSnapshot.val();
        console.log(snapVal);
});

Вопрос 2 (который, я думаю, в основном перефразирован): Как я могу получитьsnapVal внетогда. область применения метода?

    return change.after.ref.parent.parent.parent.child('/rooms')
.child(snapVal).child('/ins').set(afterData);
      // snapVal should go above
   });

Сообщение об ошибке:ReferenceError: snapVal не определено

Ответы на вопрос(1)

Ваш ответ на вопрос