Como clonar um nó para outro caminho com base em um valor de referência do caminho inicial no Google Cloud Functions?

Estou tentando clonar os dados de um nó "original" (assim que eu crio os dados) em um caminho baseado no caminho do nó original.

Esta é a minha estrutura de dados:

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,
      }
    }
  }

Minha função de nuvem agora é assim:

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... 

Pergunta 1) Como posso obter o valor deste ref / node?

Meu código continua tentando obter o valor assim.

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

Pergunta 2 (que eu acho que é basicamente a pergunta 1 reformulada): Como posso obter osnapVal fora daentão. escopo do método?

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

Mensagem de erro:ReferenceError: snapVal não está definido

questionAnswers(1)

yourAnswerToTheQuestion