问题
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}`) ...
my db record looks like this:
What am I doing wrong?
回答1:
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')
来源:https://stackoverflow.com/questions/62071774/firebase-get-data-by-timestamp