Firestore query by date range

前端 未结 9 910
悲&欢浪女
悲&欢浪女 2020-12-02 12:11

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

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 12:20

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

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

提交回复
热议问题