So currently building an app that connects users with stores. When a user presses connect, he connects with the first store available in the queue. Once a connection is established, the user can chat with that store about potential deals.
Currently, when a user presses connect, I am ordering the queue of stores in stores collection by timestamp and I am fetching the first document and then proceed to establish the connection.
This is incorrect because I must not connect the user with a store he has already connected with before. How do I exclude an array of already connected document IDs while doing the order by and limit to operations? Wherefield is only useful if I want to filter by fields. In this case, I want to exclude certain documents while fetching documents.
fileprivate func checkIfConnectionExists(){
Firestore.firestore().collection("stores").order(by: "timestamp").limit(to: 1).getDocuments { (querySnapshot, error) in
if let error = error{
return
} else {
if let docs = querySnapshot?.documents, !docs.isEmpty{
for document in docs{
//HERE I WRITE THE CODE THAT ESTABLISHES THE CONNECTION BETWEEN THE STORE AND THE USER
}
} else {
self.connectionUnavailable()
}
}
}
}