如何从文档快照获取Firestore文档ID? [英] How to get firestore document ID from document snapshot?

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

问题描述

QuerySnapshot querySnapshot = await _collectionRef   
                                  .limit(1)
                                  .orderBy('date')                                                                    
                                  .getDocuments();
var list = querySnapshot.documents;

querySnapshot.documents.map((document) { 
    print('Document : $document'); // not printing anything.
  });

if(list.length > 0) {
   print('ID : ${list[0].documentID}'); // not working
}

这是我尝试过的确切代码... 代码有什么错误?

This is the exact code i tried... What is the mistake in the code?

推荐答案

根据 API文档 DocumentSnapshot 具有 documentId 属性,所以我希望这可以工作:

According to the API documentation, DocumentSnapshot has a documentId property, so I would expect this to work:

querySnapshot.documents[0].documentID

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

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