skip to Main Content

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:
enter image description here

here’s what i’ve tried:
enter image description here

This is the error I get: Invalid document reference. Document references must have an even number of segments, but membres/UVLPL9kxP1hGuiwCStS4oDLJvxo1/projets has 3.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. addDoc works like that:

    addDoc(CollectionReference //i.e collection(db, "path"), element)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search