I have realized that you cannot query for a "does-not-contain" array in Firestore which is very problematic. (I cannot query for that which a user has not seen, I am however wondering if you can compare collections and therefore highlight similarities)
Is there a way to make 2 queries to Firestore and afterward compare if similar fields exist within the collections?
For example, if I could make 2 queries to compare the collection "AllNews" with the collection "MyNews" and therefore be able to highlight "uid1" & "uid2" within a collectionviewcell since the items exist within both collections. This way a user can see all items within "AllNews" while at the same highlighting the ones he already has in his collection "MyNews".
AllNews
uid1 *
uid2 *
uid3
uid4
uid5
MyNews
uid1 *
uid2 *
Fetching the "AllNews" collection.
I would also need to fetch the "MyNews" collection somehow...
func fetchAllNews(firebasePath: Query) {
let allnewsref = firebasePath
allnewsref.getDocuments() { (querySnapshot, err) in
if err == nil && querySnapshot != nil {
var tempNews = [CreatedAllNews]()
if querySnapshot!.documents.count > 0 {
self.dataExists()
for document in querySnapshot!.documents {
let data = document.data()
let createdAllNews = CreatedAllNews(newsId: document.documentID)
tempNews.append(createdAllNews)
}
}
self.news = tempNews
}
}
}
Somehow comparing arrays and highlighting the cell if a field exists within both arrays.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! AllNewsCollectionViewCell
cell.set(createdAllNews: allNews[indexPath.row])
//If item exists within array "createdAllNews" and array "MyNews"
cell.layer.borderColor = UIColor.blue
}
return cell
}
Optimally I would like this to work efficiently even though there is a large database. Is this possible or is there another way to achieve a similar end result? Any nudge towards a solution is appreciated.