Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda