I want to query all users that a user (user1) is friends with, in one query with firestore.
Currently, I have a "friends" field in each user object, so to get the users who are friends w user1, I call:
friendsOfUser1 = db.collection('users').where('friends', 'array-contains', user1).stream().
This works well when users only have < 100 friends, but after that the user objects get very large since the user.friends array has many values. This makes receiving user objects expensive.
Is there a way to store the friends array outside of the user documents while still being able to query a user's friends in one query? This is what the structure is now:
user1: {friends: ["user2", "user3", "user7", "user9"], name: "John Sci"}
user2: {friends: ["user1", "user4", "user8", "user12"], name: "Elmo Square"}
user3: {friends: ["user1", "user7", "user9"]}
so db.collection('users').where('friends', 'array-contains', user1).stream() will give [user2, user3].