I am building an app using Firebase Firestore as a BaaS.
But I am facing a problem when I try to create a feed/implement full-text-search on my app.
I want to be able to search through all the users posts, the problem is, the users posts are structured like this in the Firestore Database:
Posts(collection) -> UserID(Document) -> user posts(subcollection that holds all userID posts) -> actual posts(separate doccuments within that collection)
I want to loop through every user's user posts subcollection and fetch all data for the feed, and also to implement it with a full text search app like Algolia or ES.
I can loop through a specific user ID(code below), but being a beginner, I couldn't find a way to loop through all of them and fetch all of them.
firebase.firestore() .collection('allPosts') .doc('SPECIFIC_USER_ID') //-> Here I have to loop through all docs in that collection .collection('userPosts') .orderBy("creation", "asc") .get() .then((snapshot) => { let posts = snapshot.docs.map(doc => { const data = doc.data(); const id = doc.id; return { id, ...data } }) setUserPosts(posts) }) }
Would love some help!