Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Using variables in Firebase path with vanilla JS when updating multiple keys

I'm trying to update multiple paths at the same time with my Firebase database, but each path requires variables to define:

const update_referral_path = "referrals/" + referral_code.trim() + "/" + current_user_id
const new_referral_path = "profile/" + current_user_id + "/user_dict/profile/referral_code"

I'm using this code to update it, but Firebase as expected updates the database with the literal string "update_referral_path" and "new_referral_path."

    admin.database().ref().update({
        update_referral_path: current_time,
        new_referral_path: generated_referral_code
    }, error => {
        if (error) {
            console.log("updateReferral failed")
            return false
        } else {
            console.log("updateReferral succeeded")
            return true
        }
    })

I've seen ways to use variables in Angular with backticks and double brackets, but I'm unsure how I can do this in vanilla JS and can't find any examples of people doing so? What are my options?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To use the value of the variable in a key, use [] notation:

admin.database().ref().update({
    [update_referral_path]: current_time,
    [new_referral_path]: generated_referral_code
}, error => {
    ...

You can also build a literal JSON object outside of the update call:

let updates = {};
updates[update_referral_path] = current_time;
updates[new_referral_path = generated_referral_code;
admin.database().ref().update(updates);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda