In my firestore database, I have user generated posts which have a topic element attached to it.
Users subscribe to topics and they are stored on the user's profile database.
Now, I need to loop through all of the user's subscribed topics, and I want to find the most recent 10 posts that have a topic that is also in the user's subscribed_to object.
So what I'm doing is this:
//establish the query.
var query = this.afs.collection('posts').ref
.orderBy('created', 'desc')
.limit(11);
//loop through the user's subscribed_to data
for(var topic in this.userData.subscribed_to) {
//add each topic to the where query
query = query.where('topic', '==', topic);
}
query.get().then((results) => {
//..rest of the code
})
The problem seems to be that the query adding the where's as an AND instead of an OR, meaning a post would need all the topics that the user is subscribed to...
How can I do it that it goes by OR and finds the posts that contains topic x, or topic y, or topic z...