我希望在 firebase 中进行查询,以按生日月份获取所有 child 。 例如,月份是四月(04),所以我想在我的示例中获取 user1、user2、user4
不确定是否需要在 startAt 查询中使用或以什么方式执行。
let month = '04';
firebase.ref('/UserTest').startAt(month).once('value',snapshot=>{
snapshot.forEach((childSnapshot)=>{
})
})
最佳答案
您需要单独存储月份的字段,然后您可以使用 equal(month_here)
来检索 4 月份的所有用户:
firebase.ref('/UserTest').orderByChild("month").equalTo(month).once('value',snapshot=>{
snapshot.forEach((childSnapshot)=>{
var users = childSnapshot.key;
})
})
此 var users = childSnapshot.key;
将检索用户
更多信息在这里:
https://firebase.google.com/docs/reference/js/firebase.database.Query
关于javascript - firebase 按生日月份获取 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50022327/