如何获取Firestore集合的文档ID [英] How to get document ids of a firestore collection

查看:94
本文介绍了如何获取Firestore集合的文档ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的壁炉架。我想将 RecodeBook收藏集的文档ID放入dart列表中。

Here is my firestore strcuture. i want to get 'RecodeBook' collections's document id's to a List in dart.

我在这里到处寻找解决方案。但我找不到。

i looked everywhere for a solution here. but i could not find.

这是firestore的图片链接

推荐答案

使用getDocuments()方法,您将获得querysnapshot。使用.documents获取DocumentSnapshot。

Use getDocuments() method, you'll end up with querysnapshot. Get DocumentSnapshot with .documents. Print their documentId in a loop.

QuerySnapshot querySnapshot = await Firestore.instance.collection("RecodeBook").getDocuments();
var list = querySnapshot.documents;
list.forEach((f) {
  print(f.documentID);
});

这篇关于如何获取Firestore集合的文档ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆