我如何从 firebase 获取 swift3 中值等于某个值的数据。
在 MySQL 中将是 "SELECT * FROM users WHERE type = 'brown'";
我如何在 Firebase 中编写 where
部分?
我有这个数据库
我想从 month
== currentMonth
中获取所有数据(我有一个 currentMonth
变量)
最佳答案
您可以像这样查询
:
let ref = Database.database().reference()
ref.child("Budget")
.queryOrdered(byChild: "Month")
.queryEqual(toValue: "November")
.observe(.value, with: { (snapshot: DataSnapshot) in
var array:[Budget] = []
for budgetChild in snapshot.children {
let budgetSnapshot = budgetChild as! DataSnapshot
let budgetDictionary = budgetSnapshot.value as! [String:String]
let budget: Budget = Budget()
budget.description_ = budgetDictionary["Description"]
budget.month = budgetDictionary["Month"]
budget.type = budgetDictionary["Type"]
budget.value = budgetDictionary["Value"]
array.append(budget)
}
})
关于iOS Firebase 获取值等于某物的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47273903/