1

I'm using firebase for a project and I have a question. I have an entry in my database with a reference to another object. When I fetch it, I get my entry and after I can get the data link to my refs by doing a get(). Doing this takes a lot a time and I have to manually get all the refs in my entry. Is there a way to fetch my data and include all the children refs data in one call?

firestore.collection('xxx').doc(id).collection('employees')
    .onSnapshot(async (collectionDocs) => {
        const employees = _.map(collectionDocs.docs, (employeeDoc) => {
            return employeeDoc.data();
        });

        for(const e of employees){
            if(e.roleRef){
                await e.roleRef.get()
                .then((roleDoc) => {
                    const role = roleDoc.data();
                    e.role = role;
                });
            }
        }
    });
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441

0 Answers0