Search code examples
firebasegoogle-cloud-firestoregoogle-cloud-functionsfirebase-extensions

how do I get subcollection path in firestore


I'm fairly new to firebase and I'm trying to get the path to one of my subcollections in order to install a firebase extension.

This is how my JSON looks like

firebase-image

The issue is I'm trying to get the subcollection "comments" under each "post" document as required by the extension

extension-configuration

I'm aware I can use collection groups and simply give it "comments" however in my case the path is required by the extension

I tried doing post/comments however it would detect that the path is incorrect and would throw out an error

I tried post/${postId}/comments however that simply wouldn't work

I know the extension does work because something like /post/c9902c40-6e63-11ed-b700-2d9d4e8231b7/comments does work for that one branch


Solution

  • What you're trying to enter would be called a "collection group", which is all of the collections with the same name, no matter where they are located. This extension is asking you for just a collection, which means you can specify only one complete path without wildcards (it can't be a collection group). I'd suggest sending feedback to the author of the plugin and ask for collection group support. I'm guessing you're using this one:

    https://github.com/conversationai/firestore-perspective-toxicity

    Either that, or put all comment documents in a single collection and point the extension there instead.