[英]Querying subcollection's field and get parent DocumentSnapshot in firestore android
我的要求,如果其他用户在他们的手机上保存了我的号码,我想获取他的个人资料数据。现在我正在查询联系人子集合内的移动字段。当我进行查询时,我得到子集合文档的文档快照。但是,我想获得该用户的完整个人资料数据,所以,我需要获得父快照。我怎样才能做到这一点,否则我必须改变 firestore 的结构? 提前致谢
[
db.collectionGroup("contacts")
.whereEqualTo("mobile",preference.getMobile()?.number)..get().addOnSuccessListener { snapShots ->
val list = ArrayList<UserProfile>()
for (s in snapShots) {
//here i'm getting the contact data
val contact = s.toObject(ModelMobile::class.java)
//My need is getting userProfile Data
/* val contact = s.toObject(UserProfile::class.java)
list.add(contact)")*/
}
}
在对contacts 子集合进行查询之后,您将需要对父文档进行另一个查询。 在单个查询中同时获取它们是不可能的。
for (s in snapShots) {
var parentDocRef = s.reference.parent.parent
// Now you have to get() the parentDocRef to get its contents
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.