来自javascript的Firestore文档的服务器时间戳

时间:2017-12-17 15:03:03

标签: javascript firebase google-cloud-firestore

我希望每次创建(或更新)时都在文档上插入创建的日期。

我尝试使用SELECT SP.svc_pt_id, SP.device_id, DV.mfg_serial_num, dc.name, Substr(dc.name, 26), ctpt.ctpt_name, ctpt.ctpt_multipler, ctpt.ctpt_id FROM eip.svc_pt_device_rel SP, eip.device_class dc, eip.device DV left outer join (SELECT SP.svc_pt_id ctpt_svc_pt_id, SP.device_id CTPT_ID, dc.name CTPT_name, Substr(dc.name, 26) CTPT_multipler FROM eip.svc_pt_device_rel SP, eip.device_class dc, eip.device DV WHERE SP.eff_start_time < To_date('20170930','YYYYMMDD') + 1 AND SP.eff_end_time IS NULL AND dc.id = DV.device_class_id AND DV.id = SP.device_id AND dc.name LIKE '%CT/PT%' ORDER BY SP.svc_pt_id) ctpt ON ctpt_svc_pt_id = SP.svc_pt_id WHERE SP.eff_start_time < To_date('20170930', 'YYYYMMDD') + 1 AND SP.eff_end_time IS NULL AND dc.id = DV.device_class_id AND DV.id = SP.device_id AND dc.name NOT LIKE '%CT/PT%' --and SP.SVC_PT_ID = ctpt.ctpt_svc_pt_id(+) ORDER BY SP.svc_pt_id; ,但它会抛出firebase.database.ServerValue["TIMESTAMP"]

任何工作手册?

1 个答案:

答案 0 :(得分:2)

我为所有数据库文档创建和更新创建了一个实用程序函数。 serverTimestamp()返回一个sentinel,当文档被写入/更新时,它会被转换为实际的时间戳。

 private getNewMetadata(key?: string): shareTypes.documentMetadata {
    let metadata: shareTypes.documentMetadata = {
      createdAt: this.timestamp(),
      updatedAt: this.timestamp(),
      id: key || ""
    }

    return metadata;   }

 private timestamp(): any {
        return firebase.firestore.FieldValue.serverTimestamp()
      }