0

Is there a way to check for value within an array if you're querying for a specific document ID?

This doesn't work:

let userID = Auth.auth().currentUser?.uid ?? "nil"
let db = Firestore.firestore()
db.collection("users").document(userID).whereField("favorites", arrayContains: productID)

Seems like you can only use .whereField directly after declaring the collection, but not on the document.

enter image description here

1 Answer 1

1

The idea of the where methods is to find docs in a collection satisfying some criterion.

If you've already got a doc ref, just get() it and check the array in the client.

Alternatively, query the collection with where, and see if your user id is one of the ids in the resulting snapshot.

Sign up to request clarification or add additional context in comments.

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.