syraxidlemind
syraxidlemind6mo ago

Firebase filter condition = document reference in another collection

I'm struggling with a basic Firebase Collection Query filter. I have a collection, 'chapters', each of which has a 'book_id' field which stores a reference to the book document they belong to. When I want to query for all chapters with a particular book_id, I get empty results. If I omit the filter, all chapters are returned. Please help me understand what is wrong with this filter syntax: [{"field": "book_id", "operator": "==", "value": "/books/someIdValue"}]
Solution:
@syraxidlemind - you are correct, passing the reference as string wont work because you need to convert it to a valid firestore reference to be able to use it in a filter. If you copy this workflow and paste it, then the collection query node being used here will convert strings such as "users/user123" to a valid firestore ref and the filtering should work.
Jump to solution
5 Replies
ihappynesss
ihappynesss6mo ago
I would try LLMs to validate the query.
Gaurav Chadha
Gaurav Chadha6mo ago
the filter looks correct, just, could you check if the value is a valid string, it seems a reference type?
syraxidlemind
syraxidlemind6mo ago
Hi @Gaurav Chadha , the filter is a firestore reference, not a string. Do I need to handle it differently?
Solution
Luis
Luis6mo ago
@syraxidlemind - you are correct, passing the reference as string wont work because you need to convert it to a valid firestore reference to be able to use it in a filter. If you copy this workflow and paste it, then the collection query node being used here will convert strings such as "users/user123" to a valid firestore ref and the filtering should work.
syraxidlemind
syraxidlemind5mo ago
Magic, thank you @Luis!