Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDocParentId? #33

Open
pnaylor opened this issue Mar 16, 2020 · 6 comments
Open

getDocParentId? #33

pnaylor opened this issue Mar 16, 2020 · 6 comments
Labels

Comments

@pnaylor
Copy link

pnaylor commented Mar 16, 2020

It seems like it would be very helpful for working with subcollections if there was a function in the API to fetch the parent ID of a document, unless there is already some easier way to do this that I am not aware of yet.

Thank you!

@kossnocorp
Copy link
Owner

Hey, sorry for the long response. There's no easy way atm, but it should be easier to add. Right now you can parse the collection's path. You can access it via someDoc.ref.collection.path.

@pnaylor
Copy link
Author

pnaylor commented Apr 13, 2020

I see ok, thank you for the feedback.

@pnaylor pnaylor closed this as completed Apr 13, 2020
@kossnocorp
Copy link
Owner

You're welcome. I'd like to keep the issue open, so I won't forget to add it.

@kossnocorp kossnocorp reopened this Apr 14, 2020
@braaar
Copy link

braaar commented Oct 28, 2022

I found this tip useful!

The path looks like this for a document in a subcollection named thisCollectionName:
'parentCollectionName/parentDocumentId/thisCollectionName'

A simple .split('/') does wonders here :)

@tianhuil
Copy link

tianhuil commented May 5, 2024

Is there any progress? It would be good to have ref.parentRef (which uses .split('/') to obtain the parent and a ref.getParent to get the typed parent.

Firestore supports this: https://stackoverflow.com/a/56223319

@kossnocorp
Copy link
Owner

@tianhuil hey! There has been no progress on the issue; however, it has become possible with the new v10 API. I will work on it when I have a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Planned
Development

No branches or pull requests

4 participants