I'm working on a project using Google firebase firestore. I wanna implement a filter on my search for users. Imagine the search for only active users with a checkbox which users can select.
let db = Firestore.firestore()
let reference = db.collection("users").limit(to: 20)
//FILTER
if showOnlyActiveUsersBtn.isSelected {
reference.whereField("active", isEqualTo: true)
}
reference.getDocuments(completion: {(querySnapshot, error) in
.....
})
I expected this would return the result with only users who have the field "active: true", however, it returned the same list as the query without the filter... if I write like:
let db = Firestore.firestore()
let reference = db.collection("users").limit(to: 20).whereField("active", isEqualTo: true)
reference.getDocuments(completion: {(querySnapshot, error) in
.....
})
It returns the result I expected first. I don't have any idea why my filter doesn't work. How can I add logical "AND" condition with user-friendly way?