如果我在 Firebase 中有以下结构:
{
"images": {
"first_image": {
"url": "https://ima.ge/first_image",
"uploader": "john",
"start": "1465920841",
"end": "1466920841"
},
"second_image": {
"url": "https://ima.ge/second_image",
"uploader": "louis",
"start": "1465920987",
"end": "1476920987"
},
"third_image": {
"url": "https://ima.ge/third_image",
"uploader": "peter",
"start": "1465920990",
"end": "1484920990"
}
}
}
是否可以查询当前时间戳在“开始”和“结束”之间的所有图像?因此,如果当前时间戳(自 Unix 纪元以来的毫秒数)是 1475920987
,它将返回 second_image
和 third_image
而不是 first_image
因为时间戳不在开始和结束的范围内。
恐怕这是不可能的,因为在其他 stackoverflow 问题中,用户指出多个查询是不可能的。因此,如果我想做一个投票系统,用户可以决定何时允许其他人投票,是否可以只向用户显示可投票的图像?即使不允许多次查询?
我正在使用 iOS 和 Android Firebase SDK,但不需要特定语言的答案。
最佳答案
您可以在单个查询中同时使用 queryStarting(atValue:)
和 queryEnding(atValue:)
。
所以你需要这样的东西:
let query = Database.database().reference().child("images")
.queryStarting(atValue:<startTimestamp>)
.queryEnding(atValue:<endTimestamp>)
关于swift - Firebase 中其他两个值之间的查询值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37867091/