firebase - 当您拥有该文档的数据时,如何访问 firebase 中的 documentID
问题描述
从下面的代码: data 是文档的数据,我想使用该数据来引用同一文档的 documentID。
return GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) {
return ProductScreen(
// sends the id of that particular doc
productID: data.id,
);
},
));
},```
I have the data of that particular document, and i want to use that data to reference the id of the document
解决方案
您可以where()
在查询中使用方法。
FirebaseFirestore.instance
.collection('users')
.where('productID', isEqualTo: "TheProductID")
.get()
.then((snapshot) {
print(snapshot.size)
var matchedDoc = snapshot.docs
// run a loop on matchedDoc and access the reference property
});
此查询将返回 aQuerySnapshot
并将包含 productID 字段等于提供的值的所有文档。然后您可以使用每个文档的reference
属性QueryDocumentSnapshot
来获取它们的DocumentReference
.
推荐阅读
- r - 如何使用 r 中的聚合函数选择要删除的变量
- c++ - 将静态内存更改为动态 C++
- javascript - Angular 9 用于将 array1 的 OR 条件迭代到数据 array2 并连接结果
- flutter - 带有换行文本和行元素的卡片
- firebase - 如何使用密码匿名访问 Firestore 文档
- algorithm - 函数的渐近分析
- azure - 我可以在没有 Microsoft 帐户的情况下登录 Azure(或 Microsoft 356 产品)吗?
- swift - 无法将参数从闭包传递给 Swift 中的函数
- database - ORA-01012 错误。SYSRESV 的 Windows 对应项是什么?
- python - 如何使用 Python 使用重复列值来分隔数据框中的行?