Reputation: 2623
I am working on a small iOS app, using Swift and Cloud Firestore database.
I have collection (A) each document of which contains field with reference to another collection(B). Why question is how to query that field?
let doc = "merchant"
let ref = db.collection(doc).whereField("subscribers",arrayContains: Session.current.user!.uid!)
ref
with reference field from collection A like so db.collection("appointment").whereField("merch_ref", isEqualTo: ref).addSnapshotListener { snapshot, error in
if let snap = snapshot {
for item in snap.documents {
print(item.data())
}
}
}
When I execute that I'm getting an error
Terminating app due to uncaught exception 'FIRInvalidArgumentException', reason: 'Unsupported type: FIRQuery'
Can you point me in the right direction
Thanks
Upvotes: 0
Views: 1861
Reputation: 813
Here is how I use reference type to query a collection (node.js):
let myCollectionADocument = await admin.firestore().collection("collection_a").doc("documentId").get();
let myCollectionB = await admin.firestore().collection("collection_b").where("collection_a_id", "==", myCollectionADocument.ref).get();
Upvotes: 2
Reputation: 317372
Your ref
isn't actually a document reference type object. The compiler is telling you it's a Query type object. It just contains all the parameters for the query you defined. It doesn't actually have any document data in it.
If you want to get the matching documents from that query object, you should follow the instructions in the documentation. You will need to execute the query, iterate the result snapshots, and use those results as a basis for comparison.
Upvotes: 0