Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!