Firestore document query on a subcollection

I’m trying to do a Document query on Firestore inside a subcollection but it seems that I’m doing something wrong.
For instance, if I want to do a query to find a document having myField to “searchField” inside the MY_SUBCOLLECTION subcollection, I’m doing this:

However, it seems that the from field of the query doesn’t expect a path to a specific subcollection.

Node output

Could someone please explain to me how I can manage this ? Thank you in advance !

Hi @Ronan :wave: Welcome to the community :tada:

You should in theory be able to use a full JSON payload to achieve this - check out this post from my teammate @MutedJam :

I was trying to look into how to get sub-collections for you for a bit - but I’m afraid I’m honestly fairly stuck :sweat: I thought that this would be the way to go: StructuredQuery  |  Firebase

But even with that selector, I was only able to get the main collection’s data. Perhaps someone with a better understanding of Firestore can jump in here for you - I tried to also pull in @MutedJam on this one, and sadly he isn’t too sure either. :bowing_man:

My best advice as well would be to disable the “simplify” option on the Firebase node as you play around, too. If you’re trying to run these queries, n8n logic may not output the data in the way you want.

1 Like

Thank you ! I love this tool already, thank you for your work !

As far as I understand CompositeFilter is useful to combine filters but the from field isn’t affected by this.

The documentation for StructuredQuery  |  Firebase doesn’t seem to mention subcollections so I’m a bit lost too.

For those who are interested, I tried an alternative by making an http request directly.
It allows to search documents for a subcollection which have a specific field (here myField). However, I still didn’t managed to apply a filter on this document list to only receive the one which have myField to a specific value.
At least it allows you to search within a subcollection, but it still doesn’t allow you to obtain a document with a specific field value.

Here is the request:[YOUR_PROJECT_ID]/databases/(default)/documents/MY_COLLECTION/byHhQXxmeslQTgvJYs5E/MY_SUBCOLLECTION?orderBy=myField
(Don’t forget to replace [YOUR_PROJECT_ID] with your Firebase project id)

Here is the node used to do it:


Thank you so much for posting this, @Ronan !

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.