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

查看:30
本文介绍了如何从文档快照中获取 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天全站免登陆