Save document_key as separate property

Hi!

I recently ran into a problem in my current project that I don’t know how to solve.

When a user creates a new document in one of my firebase collections (called Collections) I need to be able to fetch the document_key of that collection and store it as a separate property inside the newly created collection, all in the same interaction. The reason this is needed is to make it indexible by the following query:

where(" CollectionID “, “==”, “$slot(’ ds_SelectedCollectionID ')”).orderBy(” CollectionDate ",“desc”)

This is not possible today without some sort of custom script but unfortunately I don’t know how to code. Is there anyone here that has ran into a similar scenario and knows how to solve it?

Thanks in advance

Viktor

2 Likes

Hey, Viktor. I’m not sure whether you’re still having this problem. My friend and I just figure out that you can use the collection ID to pull up the selected document using the same data slot: CollectionID/“$slot(’ ds_SelectedCollectionID '). I hope that works for you.

Whoa. A two-year old post :astonished:

In any case, I do think every answer helps the next person searching for a solution in the forum …

If I read the question correctly, this should already be built-in. ie. Every new Document created in Firestore has a (hidden) column named “document_key”, where it holds the Document ID.

See the restaurant example - search for “document_key”. The screenshot just above shows an interaction saving the Document ID (ie. document_key) of that particular Document into a ds_slot.

https://medium.com/hackernoon/the-easiest-way-by-far-to-build-a-real-react-firebase-web-app-5dc6fa6f1b61

1 Like