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

122
Vistas
Getting an Error when Trying to Update Firebase Realtime Database

The code is giving me the error and is not updating the database:

Uncaught Error: update failed: values argument contains an invalid key ([object HTMLInputElement]) in path /user-Projects/[object HTMLInputElement]/-Mne7bupWgxUwAS-GtVh. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"

const user = document.getElementById('userName');
//const uid = 0;
const project = document.getElementById('projectName');
const model = document.getElementById('modelName');
const addBtn = document.getElementById('addBtn');
const updateBtn = document.getElementById('updateBtn')

const db = firebase.database();
const rootRef = db.ref('users')
const projRef = db.ref('Projects')

addBtn.addEventListener('click', (e) => {
    e.preventDefault();
    //const autoId = rootRef.push().key
    //console.log('Add button clicked')

    //Project Entry
    var projectData = {
        owner: user,
        uid: user,
        title: project    
    };

    //Get a key for a new project
    var newProjectKey = db.ref().child('Projects').push().key;
    console.log(newProjectKey);
    var updates = {};
    updates['/Projects/' + newProjectKey] = projectData;
    updates['/user-Projects/' + user + '/' + newProjectKey] = projectData;

    db.ref().update(updates);


});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're using your user variable in the path, which is initialized as

const user = document.getElementById('userName');

So you're trying to put an HTML element into the path, instead of just the current value from that element, which is what I think you may be trying to do.

To use just the current value of the userName element, use:

const user = document.getElementById('userName').value;
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