Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

How to access virtual documents in Firestore through Firebase SDK?

I am a beginner and my firestore database has a collection which has documents and each document has a subcollection without any other fields. I can't find a way to access the ID of the empty document and get the subcollection associated with the doc using the SDK. I could do it on console but I have to too much to do and cannot also make changes to my application for now so I need to use the SDK. Please suggest me some way to access them like the console.

question from:https://stackoverflow.com/questions/65916307/how-to-access-virtual-documents-in-firestore-through-firebase-sdk

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you know how the CollectionReference of the sub-collection, you can easily get the parent DocumentReference with parent property of the CollectionReference. From the DocumentReference you just need to use the id property.

You didn't share much details on your data model, so it is difficult to give more guidance on how to find the CollectionReference. Mark's answer presents some possible approaches.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...