[英]Firebase queryEquals Not Returning Values in Swift
I have a Firebase structure that looks like: 我有一个Firebase结构,如下所示:
- key1
-key2
-key3:value
-key4:value
-key5:value
-key6:value
I am looking to return records where key3
's value equals a particular string. 我想返回
key3
的值等于特定字符串的记录。
let ref = FIRDatabase.database().reference()
let path = "Object/key1/key2"
ref.child(path).queryOrdered(byChild: "key3").queryEqual(toValue: "myvalue").observeSingleEvent(of: .value, with: {(snapshot) in
The above returns NULL. 上面返回NULL。 If I remove the
queryEqual
, all records are returned. 如果删除
queryEqual
,则返回所有记录。 I have triple checked that the "myvalue" is matching in FB as well as in the call. 我三重检查了“ myvalue”在FB中以及在调用中是否匹配。
I have the FB call in a loop as key1
and key2
change. 当
key1
和key2
更改时,我在循环中调用了FB。 In the end I only want those records (everything under key2
) returned only if key3
is equal to value I send in my queryEqual
statement. 最后,仅当
key3
等于我在queryEqual
语句中发送的值时,我才希望返回那些记录( key2
下的所有内容)。
To give the full return see below. 要获得全部回报,请参见下文。 I commented out my actual return process to just check via a simple print:
我注释掉了我的实际退货过程,只是通过简单的打印进行检查:
ref.child(path).queryOrdered(byChild: "key3").queryEqual(toValue: "mvValue").observeSingleEvent(of: .value, with: {(snapshot) in
for test in snapshot.children
{
print (test)
}
/*if let returnDict = snapshot.value as? NSDictionary
{
helperProtocol.firebaseDidReturn?(returnDict: returnDict, extraDict: extraDict, name:name)
}
else if let returnArray = snapshot.value as? NSArray
{
helperProtocol.firebaseDidReturn?(returnDict: ["array":returnArray], extraDict: extraDict, name:name)
}
else
{
helperProtocol.firebaseDidReturn?(returnDict: nil, extraDict: extraDict, name:name)
}*/
})
The issue was the depth of the query path. 问题是查询路径的深度。 From the above I was using:
从上面我正在使用:
let path = "Object/key1/key2"
The path needed to be: 路径需要为:
let path = "Object/key1"
So even though the search key ( key3
) is under key2
, the approach is to go one level higher as shown above. 因此,即使搜索键(
key3
)位于key2
之下,方法也要上一层。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.