I wish to be able to add projects in a subcollection called projects. Currently my tree is: db/membres/[membreID]/projects/(here I want project ID that firebase generates)/(information of project) Here is my firebase:
This is the error I get: Invalid document reference. Document references must have an even number of segments, but membres/UVLPL9kxP1hGuiwCStS4oDLJvxo1/projets has 3.
CodePudding user response:
The error message is quite clear: you are trying to write to a document at path /membres/$uid/projects
, but that is the path of a collection.
If you want to add a document to that subcollection, use addDoc
instead of setDoc
.
CodePudding user response:
addDoc works like that:
addDoc(CollectionReference //i.e collection(db, "path"), element)