1

What I want to do: Check if a user is following another user. Basically I want to see if the UID of the user is in the "follower" array in the document of the other user-profile.

It looks like this

I thought of the option to use the .whereField command, but then I would get more documents and not only the one that I care of.

2 Answers 2

1

You can go with array-contains operator:

https://firebase.google.com/docs/firestore/query-data/queries#array_membership

So you can write something like this:

usersRef
    .whereField("followers", arrayContains: "l47GVBdjsabjdjds")
Sign up to request clarification or add additional context in comments.

Comments

1

Get the user document (using whereField isEqualTo)and check if the followers field array contains the uid of the second user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.