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

127
Visualizações
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 Respostas
Responde à pergunta

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