I am developing an app enabling users to connect and open a chat based on similar interests.
i have a user collection, a matching collection.
i developed an action chain where the first part checks if a document in the matching collection is open - this filters and sees if the user_a in the matching collection is not the logged-in user, and the match-open bool is equal to true. if such a document does not exist, it creates a document in the matching table and sets the user_a as the logged-in user and keeps the user_b, open for a new user to connect.
Now the problem is. i have never known when to use a loop and I've never really played with it, even though am sure a loop will rather work for this sort of thing. I feel finding the collection should at least check it 3 times in about 10 seconds, and if there's still no document, then it can go ahead and create a new matching document while it waits for a new user with similar interest to connect and open a chat between them. How do I do this loop?
Is there a better way to do this?