[英]Get Document ID from Firebase Query using Flutter
If I have a collection called userNames
and I use a firebase query to search for a document that a database field uid
matches the current user ID, how do I print the document ID of the documents that contain that term?如果我有一个名为userNames
的集合,并且我使用 firebase 查询来搜索数据库字段uid
与当前用户 ID 匹配的文档,我如何打印包含该术语的文档的文档 ID?
A query can return multiple documents that match the given condition and returns a QuerySnapshot (that contains zero or many DocumentSnapshots ).查询可以返回多个与给定条件匹配的文档,并返回一个QuerySnapshot (包含零个或多个DocumentSnapshots )。
FirebaseFirestore.instance
.collection('userNames')
.where('uid', isEqualTo: FirebaseAuth.instance.currentUser!.uid)
.get()
.then((value) {
value.docs.forEach((element) {
print(element.id);
});
});
Here value.docs
is a list of all the documents included in this snapshot and each of them has id
property (the document ID).这里的value.docs
是这个快照中包含的所有文档的列表,每个文档都有id
属性(文档 ID)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.