来自Firebase的复杂查询 [英] Complex query from Firebase
本文介绍了来自Firebase的复杂查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在,我得到了如下所示的数据结构。
当用户创建日志时,它会从Firebase获取唯一的ID。这个ID保存在创建它的用户(test2@test.dk)下。
但是我想显示日志,只显示登录的用户,我如何做到这一点?现在,我只能得到关键,但我需要的数据,如持续时间和startDate。
日志
-KVMbJKN1i2vAxzutiYq
持续时间:14
开始日期:28/10/2016
-KVMbLL4i_9dwaRZ9REB
持续时间:28
开始日期:2016年1月9日
-KVMiLwoSY34TZpf8mST
持续时间:14
开始日期:2016年2月2日
用户
Edl7nDpJWIdNmDVUDn87p31d9mN2
电子邮件:测试@测试。 DK
姓:测试
IMAGEURL:URL
名字:测试
提供商:Facebook的
KX6DRd0k5fasEaqB8vJWiXkp69L2
电子邮件:test1@test.dk
名字:test1
imageUrl:URL
姓氏:test1
提供者:Firebase
WRgxyjSpQlUPmeJwfF9I7PhpvHs1
电子邮件:test2@test.dk
姓:TEST2
IMAGEURL:URL
名字:TEST2
登录
-KVMbJKN1i2vAxzutiYq:真正的
-KVMbLL4i_9dwaRZ9REB:真正的
-KVMiLwoSY34TZpf8mST:TRU e
提供者:Firebase
解决方案
<$ startDate ():{(c:c,c,c,c,c,c)中的一个或多个参数,FIRDatabase.database(),引用(),child(user / \(FIRAuth.auth()!. currentUser!.uid)/ logs userSnap)在
如果让SnapDict = userSnap.value为? [String:AnyObject] {
在SnapDict {
FIRDatabase.database()。reference()。child(logs / \(each.key) ).observeSingleEvent(of:.value,with:{(Snap)in
$ b print(Snap.value)
})
}
}
})
I need to join my two tables from Firebase. Right now, i got the data structure as shown below.
When a log is created by a user, it gets a unique ID from Firebase. This ID is saved under the user who created it (test2@test.dk).
But i want to show the logs, only to the user who is logged in, how do i achieve this? Right now, i can only get the key, but i need the data such as duration and startDate.
logs
-KVMbJKN1i2vAxzutiYq
duration: 14
startDate: 28/10/2016
-KVMbLL4i_9dwaRZ9REB
duration: 28
startDate: 01/09/2016
-KVMiLwoSY34TZpf8mST
duration: 14
startDate: 2/2/2016
users
Edl7nDpJWIdNmDVUDn87p31d9mN2
email: test@test.dk
firstName: test
imageUrl: URL
lastName: test
provider: Facebook
KX6DRd0k5fasEaqB8vJWiXkp69L2
email: test1@test.dk
firstName: test1
imageUrl: URL
lastName: test1
provider: Firebase
WRgxyjSpQlUPmeJwfF9I7PhpvHs1
email: test2@test.dk
firstName: test2
imageUrl: URL
lastName: test2
logs
-KVMbJKN1i2vAxzutiYq: true
-KVMbLL4i_9dwaRZ9REB: true
-KVMiLwoSY34TZpf8mST: true
provider: Firebase
解决方案
To get the duration startDate , just query it to the desired location of the specific node:-
FIRDatabase.database().reference().child("user/\(FIRAuth.auth()!.currentUser!.uid)/logs").observeSingleEvent(of: .value, with: {(userSnap) in
if let SnapDict = userSnap.value as? [String:AnyObject]{
for each in SnapDict{
FIRDatabase.database().reference().child("logs/\(each.key)").observeSingleEvent(of: .value , with : {(Snap) in
print(Snap.value)
})
}
}
})
这篇关于来自Firebase的复杂查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文