![](/img/trans.png)
[英]How to add Document with Custom ID to firestore in firestore 9
[英]Firestore How to retrieve document's autogenerated id in the past?
在 Firestore 中,我在子集合中添加了一個文檔,我不知道它的 ID,因為它是過去添加的,但我知道它的路徑。 如何獲取它的id? 我應該在創建時保存它的 id 嗎?
謝謝
我不知道它的 id 因為它是過去添加的,但我知道它的 path 。
如果“我知道它的路徑”指的是Document path ,那么 Document ID 是路徑的最后一個元素,其中元素用斜杠分隔。 例如rootCollectionName/parentDocId/parentCollectionName/docId
。
如果使用“我知道它的路徑”你指的是子集合的路徑,那么你可以查詢子集合並獲取第一個文檔,因為集合中只有一個文檔。
例如 Dart:
QuerySnapshot querySnapshot = await Firestore.instance.collection("rootCollectionName/parentDocId/parentCollectionName").get();
var documentID = querySnapshot.docs[0].id;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.