我有以下数据结构:
attendance
--- 2020-02-09-PM
--- 2020-02-11-PM
--- 2020-02-16-AM
--- 2020-02-16-PM
--- 2020-02-18-PM
例如,我想获取 2020-02-16 的日期,我需要 PM 和 AM。所以我想查询我的数据库以仅获取该数据。
这是我的尝试:
function getAttendanceCount(orgUid, dates) {
orgUid.forEach(uid => {
dates.forEach(date => {
const getAttendCount = fDB.ref(`organization/${uid}/attendance`)
.orderByChild('attendance')
.startAt(date+'-AM')
.endAt(date+'-PM')
.once('value')
.then(c => console.log(c.val()));
});
})
}
我的 console.log 为空。 知道如何实现这一目标吗?
最佳答案
更改此:
const getAttendCount = fDB.ref(`organization/${uid}/attendance`)
.orderByChild('attendance')
进入此:
const getAttendCount = fDB.ref(`organization/${uid}/attendance`)
.orderByKey()
您需要使用 orderByKey()
的原因是因为日期充当键,而不是作为具有值示例的 child
:
"name" : "peter"
关于javascript - 在 firebase 中查询日期的 startAt 和 endAt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60359525/