我需要使用过滤数据以获得时间戳匹配的特定数据。
例如,我需要arrivalTime
与精确日期和时间字段(数据库中的时间戳记字段)匹配的数据。
我在下面尝试,但没有返回任何数据。
_arrivalTIme = moment(
`${todaysDate.format('YYYY/MM/DD')} ${_arrivalTIme}:00`,
).toDate();
// _arrivalTIme: Thu May 28 2020 09:00:00 GMT-0600 (Mountain Daylight Time)
return firestore()
.collection('mainCol')
.doc(todayDate)
.collection('subCol')
.where('arrivalTime', '==', `${_arrivalTIme}`) ...
我在做什么错?
答案 0 :(得分:3)
您正在将数据库中的日期字段与代码中的字符串进行比较。这种比较永远不会是真的。
您要么需要获取与数据库中的值完全相同的Timestamp
值,要么(通常)进行范围检查:
return firestore()
.collection('mainCol')
.doc(todayDate)
.collection('subCol')
.where('arrivalTime', '>=', new Date('2020-05-28 08:00:00')
.where('arrivalTime', '<', new Date('2020-05-28 08:01:00')