0

So I tried to create a page to add new friends in my IOS swift app. So, I first tried where "id" is not in AllMyFriendsIds.

  db.collection("users").whereField("id",notIn: MyFriends).limit(to: limit).getDocuments(completion: { [self](snap, err) in

But with more than ten friends the program crashed. Then I tried to do where "friends" array-not-content userId but this method doesn't exist. Here is an example of the user's docs.

Here is the code that does not work so how to get all users that are not friend with us so where friends does not contain userId or where the docId or Id is not in an array(more than 10)

db.collection("users")
   .whereField("friends",notIn: [UserDefaults().string(forKey: "userId")!])
   .limit(to: limit)
   .getDocuments(completion: {

My goal is to get users that are not my friends with the most efficient technique. Because I know how to do it by separating into groups of 10 but this technique is not efficient with reading and writing and cost a lot.

  • In a developer's support site, it is easier to understand a piece of code rather than "I first tried where "id" is not in AllMyFriendsIds" or "I tried to do where "friends" array-not-content userId". [This link](https://stackoverflow.com/help/how-to-ask) may help you get a valid answer. – HunterLion Jan 14 '23 at 07:24
  • Have you tried listing all friends of user first? then try to query "users" collection where the userId is `NOT-IN` list of user's friends. – Roopa M Jan 14 '23 at 07:51
  • How big would you like the list to be? Please respond using @AlexMamo – Alex Mamo Jan 14 '23 at 10:02
  • @AlexMamo I want a list of 15 to 50 users If possible related to my friends and about my age but most importantly the users should not be my friends. – Louka Studio Jan 14 '23 at 12:44
  • 1
    Firestore is awesome at finding existing data, but finding non-existent data is a bit of a challenge. One option is to do it in code - see my answer to [this question](https://stackoverflow.com/questions/57812558/firestore-how-to-get-around-array-does-not-contain-queries) which is very similar but does not scale for very large datasets. There's another option [here](https://stackoverflow.com/questions/58903491/structuring-a-firestore-database-to-filter-by-what-is-not-in-the-array). – Jay Jan 14 '23 at 15:50

0 Answers0