Firebase按时间戳获取数据 [英] Firebase get data by timestamp

查看:57
本文介绍了Firebase按时间戳获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要过滤数据以获取时间戳匹配的特定数据.

I need to filter data using to get specific data for the timestamp match.

例如,我需要 arrivalTime 与确切的日期和时间字段(数据库中的时间戳记字段)匹配的数据.

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:

我做错了什么?

推荐答案

您正在将数据库中的日期字段与代码中的字符串进行比较.这种比较永远不会是真的.

You're comparing a date field in your database with a string from your code. That comparison will never be true.

您要么需要获取与数据库中的值完全相同的 Timestamp 值,要么(通常)进行范围检查:

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')

这篇关于Firebase按时间戳获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆