Android Firestore 搜索集合,其中文档是唯一 ID

Firestore 是否可以检索文档名称未知或唯一 ID 的文档中的数据。就像在链接的图像中一样。ID未知而名称已知,在这种情况下是否可以获取ID?数据库结构示例

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);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章