Issue: Unable to update reference: The primary argument includes an invalid key

Encountering a curious error on Firebase while working with Vue.js:

The process goes smoothly the first time, and I can execute the following function multiple times without any issues.

addSpace: function (newSpace) { 
  let userId = firebaseApp.auth().currentUser.uid;  
  const key = spacesRef.push().key;  // generating key once
  console.log(key); 
  spacesRef.child(key).update(this.newSpace); }

However, when I try to run another function (see the AddDept function below), the addSpace function throws an error:

addDept: function(space, dept, newDept, event) {
  this.newSpace = space;//get current space
  const deptKey = deptsRef.push().key; // creating Dept Key
  let spaceKey = space['.key']; 
  console.log(spaceKey)
  var deptNode = spacesRef.child(spaceKey).child("hasDepts"); 
  deptNode.child(deptKey).set(true);
  deptsRef.child(deptKey).set(this.newDept);
  deptsRef.child(deptKey).child("spaceName").set(space.name);
  deptsRef.child(deptKey).child("spaceKey").set(spaceKey);
  this.newDept.name = '';
  this.newDept.comments = '';
  this.newSpaceKey= '';
},

What could be causing this unexpected behavior?

Error: Reference.update failed: First argument contains an invalid key (.key) in path /.key. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"

I have thoroughly checked all arguments through console logging, and they appear to be correct. Additionally, I attempted to stringify the arguments but was unsuccessful. Any assistance would be greatly appreciated.

Answer №1

All it took was removing the space['.key']; line from the addDept function.

Big shoutout to @skribe for the help!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide for getting JavaScript Word Counter to function correctly in Internet Explorer

As a JavaScript beginner, I recently implemented a word counter on a form using JavaScript. It works smoothly across all browsers except for Internet Explorer. In IE9 and IE11, the word counter becomes unreliable, and at times, the entire field can become ...

Troubleshooting not locating view files in ExpressJS and implementing client-side JavaScript and CSS deployment in ExpressJS

My JavaScript file is located in the same directory as my HTML file, and I am trying to render it. I'm unsure of what I may be missing. How difficult could it possibly be? var express = require('express'); var app = express(); app.engine( ...

There was an AJAX post error that occurred due to the refusal to set an unsafe header with the name "Connection"

My custom ajax function sends data to a PHP file, but I'm encountering two errors each time the data is posted: Refused to set unsafe header "Content-length" Refused to set unsafe header "Connection" Here is my code: function passposturl(url1 ...

Using AJAX to assign PHP session variables

Is there a way to update the SESSION variable named "fullname" on Page 2 without causing the page to refresh? This is my attempt using AJAX: HTML code for Page 1: <input type="text" name="fullname" id="fullname" placeholder="Full name"> <butto ...

Overriding a shared module service in Angular from a separate module: A step-by-step guide

I am working with various modules such as SchoolModule, UniversityModule, and SharedModule The SharedModule includes a BaseService that both the SchoolModule and UniversityModule providers are utilizing as an extension When loading the SchoolModule, I ne ...

Setting the default typing language in Protractor: A step-by-step guide

Is there a way to specify a default typing language in my configuration file? While running test cases locally, I am unable to switch keyboard languages during execution as it impacts the typing language for Protractor causing the tests to fail. If you h ...

Charting data with missing values in Google Charts

I have generated a line chart using php and json to load the data. The issue I am facing is that the chart displays NULL values as 0, which does not look good. My assumption is that I may be formatting the json incorrectly, and what I really need is {"v" ...

Tips for adding a string variable to a JQuery HTML element attribute

Hi there, I've been working on a JQuery code to append data to a div element and it's been successful so far. Here is the code: $('#conversation').append('<div id="receiver"><p><b>' + username + ':< ...

What is the best way to integrate varying number formats based on user locale in UI5?

In my SAPUI5 app, I need to display numerical data based on the user's settings in the SU01 backend transaction in SAP Logon. For instance, users can specify decimal separators as: 22,000.000 (twenty two thousand) → US format 22.000,000 (twenty tw ...

Why am I seeing numbers in the output when I log the data from the res.write(data) function in Node.js?

While working with Node.js on my Raspberry Pi, I encountered an issue where reading a local file 'test.html' resulted in hex output instead of the expected HTML format. Can someone explain why this might be happening? Additionally, I am aware tha ...

Crosswalk code unable to detect electronic devices

The implementation of a rails application involves the following code snippet: <div id="sourceSelectPanel" style="display:none"> <label for="sourceSelect"& gt;Change video source:& lt;/label> <select id=" ...

Merge shared attributes into JSON with the help of JavaScript

I am looking to include a shared property in my JSON Object. Below is an example of the JSON object: data = [ { COUNTRY: 'USA', POPULATION: 300, }, { COUNTRY: 'USA', POPULATION: 50, }, { COUNTRY: 'Cana ...

Exploring the interplay between jQuery functions and the "Class" method in Javascript

Is there a way to reference a parent "class" method in Javascript from a jQuery function? Here's an example scenario: $Object.prototype.TestFunction = function(arg){ alert(arg); } $Object.prototype.foo = function(){ $(something).click(function ...

Building a single page web application using TypeScript and webpack - a step-by-step guide

For a while now, I've been working on single page applications using Angular. However, I'm interested in creating a single page application without utilizing the entire framework. My goal is to have just one .html file and one javascript file, w ...

Ways to recover information that is not typically found

My firebase database has two main trees: "tag" and "user". Each user is associated with a set of tags, referred to as preferences. Here is the structure of my database: I am trying to display a list of preferences that a specific user does not have. Exam ...

Ways to eliminate all attributes and their corresponding values within HTML tags

Hey there, I'm trying to strip away all the attribute values and styles from a tag in html Here's my Input: <div id="content"> <span id="span" data-span="a" aria-describedby="span">span</span> <p class="a b c" style=" ...

{info: "Access denied due to missing authentication credentials."} while attempting a GET request using simplejwt

I have come across several questions similar to mine, but none of the solutions seem to work for me. I am unable to access the API and I can't figure out why. I tested it with a token in Postman and it returned the correct data. Can someone please poi ...

Bootstrap typehead not activating jQuery AJAX request

I am attempting to create a Twitter Bootstrap typehead using Ajax, but nothing seems to be happening. There are no errors and no output being generated. Here is the jQuery Ajax code I have implemented: function CallData() { $('input.typeahea ...

Obtain information from the get request route in Node.js

I've been diving into nodejs and databases with the help of an online resource. As part of my learning process, I have been tasked with replicating the code below to fetch data from app.use('/server/profil'); However, I'm encountering ...

Looking for a specific phrase in the data entered by the user

I am dealing with data in ckeditor that looks like this: <p>test 1</p> <p>test 2</p> <p><img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICw ...