What I am attempting to do is create a document Reference in my Firebase database that will return me an id and a doc Reference, so I can use that id to create a path for this object's image in my storage.
So according to the firebase docs I should be able to do this:
var newPlantRef = db.collection(`users/${this.userId}/plants`).doc();
But that is returning this error:
AddPlantComponent.html:30 ERROR FirebaseError: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: undefined
So I found a work-around on Github that says I should do this:
const id = this.afs.createId();
const ref = this.afs.collection(`users/${this.userId}/plants`).doc(id);
But when I do this:
this.newPlantId = this.db.createId();
this.newPlantRef = this.db.collection(`users/${this.userId}/plants`).doc(this.newPlantId).ref;
this.newPlantRef.update({
name: 'Test1',
primaryImgURL: 'test1',
addedDate: new Date()
});
}
I get this error:
ERROR Error: Uncaught (in promise): FirebaseError: [code=not-found]: No document to update: projects/plant-app-d9298/databases/(default)/documents/users/UoV0MXMfZGhMgmMJHpiMU41aLZG2/plants/LWmM79JotgDn20hPOcA1
FirebaseError: No document to update: projects/plant-app-d9298/databases/(default)/documents/users/UoV0MXMfZGhMgmMJHpiMU41aLZG2/plants/LWmM79JotgDn20hPOcA1
Am I doing something wrong? Is there some other workaround where I can get the document id before I've done an add so my items and storage can reference that id?
setmethod instead of theupdatemethod since that particular document doesn't exist in the first place.