node.js - Firebase get data by timestamp
问题描述
I need to filter data using to get specific data for the timestamp match.
For example I need the data where arrivalTime
matches with exact date and time fields, timestamp field in database.
I am trying below but it returns no data.
_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}`) ...
What am I doing wrong?
解决方案
You're comparing a date field in your database with a string from your code. That comparison will never be true.
You'll either need to get a Timestamp
value that is exactly the same as the value in the database, or (more commonly) do a range check:
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')
推荐阅读
- javascript - 如何解决此警告 - 警告:validateDOMNesting(...):不能显示为. 下面是我的代码
- visual-c++ - 如何将整数文字指定为 WORD?
- android - 如何在 xml 数据绑定中使用表情符号?
- javascript - Navigation.navigate is not a function, navigation is undefined
- python - python的开放式高程API
- reactjs - 将一个 React 应用的 UI + 功能集成到另一个 React 应用中(如 Google Maps API)
- file - 如何使用 MPI 使用自定义子数组数据类型从文件中读取子数组?
- javascript - 如何使用正则表达式替换 .replace 脚本的确切值?
- selenium - 使用父级和兄弟级的 WebTable 的 Selenium XPath
- google-chrome - 可以使用 X-Frame-Options 嵌入网站的 Chrome 应用程序的替代品:拒绝?