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.