ios – Swift Firestore – How to check if queried users’ id have been added to field?


Im working on an online dating app and I’m trying to query users who’s ID haven’t been added to a field of the current logged in user.

My User model:

id: String

blocked: Array of user ID’s

liked: Array of user ID’s

didntLike: Array of user ID’s

Observer:
potentialMatches: Array of Users // this will be shown for the logged in user to pick from

Essentially when the logged in user makes a choice the other user’s ID gets added to one of the arrays. The problem I’m having is I need to filter users so they don’t get added or re-added when making a query. Basically I want to retrieve 10 users who haven’t blocked or swiped on. Any advice would be appreciated.

Here’s what I have for the function so far

    func GetPotentialMatches()
    {
        let uid = Auth.auth().currentUser?.uid
        let db = Firestore.firestore()
        let ref = db.collection("users").document(uid!).collection("")

        ref.whereField("id", isNotEqualTo: uid!).limit(to: 10).getDocuments{ (snap, error) in
            if(error != nil)
            {
                print("error: \(error.debugDescription)")
            }
            
            // if user id is not contained in blocked, liked, or didntLike array add to potentialMatches array
            // self.potentialMatches.append(User)
        }
    }

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img