Skip to content

How can I perform nested collection queries?  #95

Open
@Glenncito

Description

@Glenncito

I have a collection of conversations. The conversation class contains a property which is a collection of ChatMessages, which contains its own properties.

here is my oode currently:

const conversationRef = query(collection(firestore, `/Conversations`));
const conversationQuery = useFirestoreQueryData(["Conversations", user.data?.uid], conversationRef,{
 idField: "_id",
 subscribe:true
})

function getConversations(){
const snapshot = conversationQuery.data;

if (snapshot){

const conversationArray:ActiveConversation[] = snapshot.map((snapshot) => {
 
 const conversation:ActiveConversation = {
   id: snapshot._id,
   topic: snapshot.topic,
   description: snapshot.description,
   currentMessageInputValue: '',
   chatMessages: [], //want to then query this as well. 
   isLoaded: false,
   members: snapshot.members,
   isConcluded: snapshot.isConcluded,
 }
 return conversation;
})
setActiveConversations(conversationArray);

}
}

useEffect(() => {
getConversations();

 },[conversationQuery.data]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions