Android Firestore搜索集合,其中文档是唯一ID [英] Android Firestore search collection where document is Unique id
本文介绍了Android Firestore搜索集合,其中文档是唯一ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Firestore是否可以在文档名称未知或唯一ID的文档中检索数据.就像在链接的图像中一样.ID是未知的,而名称是已知的,是否可以在这种情况下获取ID?
Is it possible with Firestore to retrieve the data within a document where the name of the document is unknown or a unique id. Like in the linked image. The ID is unknown whereas the name is known, is it possible to get the ID in this instance?
db.collection("users").document(??).collection("John Doe");
推荐答案
您将查询名称:
var peopleRef = db.collection("users");
// there may multiple users if there are more then one `John Doe`
peopleRef.where("name", "==", "John Doe")
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
//Here below will list all people who's name = "John Doe", If only one then this John Doe's id no: doc.id as fallow:
console.log(doc.id, " => ", doc.data());
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
这篇关于Android Firestore搜索集合,其中文档是唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文