So I watched Cris video no how to getData from firebase. So what I am practicing currently is to get all users from my User collection. However, I want to see how can I get All users from that “users” collection, but exclude the current user (logged in user). Thank you in advance for any tips
@AppStorage(CurrentUserDefaults.userID) var currentUserID: String? // If user has a value, be String. If not, then nil. AppStorage is the SwiftUI version of calling user defaults.
@Published var users = [UserModel]()
let db = Firestore.firestore()
init() {
getAllUsers()
}
func getAllUsers() {
//Read the documents at a specific path
db.collection("users").getDocuments { querySnapshot, error in
//Check for errors
if error == nil {
// No Errors
if let snapshot = querySnapshot {
//Update users property in the main thread
DispatchQueue.main.async {
// Get all documents of users
self.users = snapshot.documents.map { document in
//Create User for each document returned
return UserModel(id: document.documentID,
displayName: document["display_name"] as? String ?? "",
email: document["email"] as? String ?? "",
providerID: document["provider_id"] as? String ?? "",
provider: document["provider"] as? String ?? "",
userID: document["user_id"] as? String ?? "",
bio: document["bio"] as? String ?? "",
dateCreated: document["date_created"] as? Date ?? Date())
}
}
}
}
else {
//Handle Error
}
}
}