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:Jump to 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.
5 Replies
I would try LLMs to validate the query.
the filter looks correct, just, could you check if the value is a valid string, it seems a reference type?
Hi @Gaurav Chadha , the filter is a firestore reference, not a string. Do I need to handle it differently?
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.
Magic, thank you @Luis!