onmyway133 / blog

🍁 What you don't know is what you haven't learned
https://onmyway133.com/
MIT License
675 stars 33 forks source link

How to query document id in array in Firestore #852

Open onmyway133 opened 2 years ago

onmyway133 commented 2 years ago

Supposed we have Book object

struct Book: Identifiable, Codable, Hashable {
    @DocumentID var id: String?
}

We should use FieldPath instead of id for query

let booksRef: CollectionReference = ...
let ids: [String] = ...

booksRef
    .whereField(
        FieldPath.documentID(),
        in: ids
    )