Firestore 按日期范围查询 [英] Firestore query by date range

查看:27
本文介绍了Firestore 按日期范围查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来查询具有日期范围的长集合.请参阅下面的示例文档.我想使用日期范围查询 startTime 字段.

I need the help to query long collection with date range. See the below example document. I wanna query startTime field using date range.

推荐答案

由于我将 dueDate 字段存储为timestamp"(而不是 stringnumber)在 Cloud Firestore 上,我这样做是为了获取截止日期为 2017 年的发票文档:

Since I have the dueDate field stored as "timestamp" (and NOT as string or number) on Cloud Firestore, I did this to get the invoice documents with a due date on 2017:

let start = new Date('2017-01-01');
let end = new Date('2018-01-01');

this.afs.collection('invoices', ref => ref
  .where('dueDate', '>', start)
  .where('dueDate', '<', end)
);

注意: dueDate 字段与 Date() 对象一起存储在 firebase 中.例如:this.doc.dueDate = new Date('2017-12-25')

NOTE: dueDate field was stored at firebase with a Date() object. e.g.: this.doc.dueDate = new Date('2017-12-25')

这篇关于Firestore 按日期范围查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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