gpt4 book ai didi

node.js - 我们如何使用 Angular 按时间戳数据类型对 Firebase Firestore 数据进行排序?

转载 作者:太空宇宙 更新时间:2023-11-04 03:17:44 25 4
gpt4 key购买 nike

我有工单发布 Web 应用程序,我只会显示那些有效且 24 小时内记录的工单(从现在开始)。

我将 Firebase Cloud FirestoreAngular 7 结合使用。

 getTicketList(){
this.ticketData =
this.fireStore.collection('ticket').doc("paid").collection("ticket-list",
ref =>
ref.where('status', '==',
"active").where("paid","==","false").orderBy("myTimeStamp");
return this.ticketData.snapshotChanges() ;
}

我们有一个键“myTimestamp”,它是 Firestore Timestamp 类型。

只想显示那些处于事件状态并且当前还有剩余时间可以预订的记录。

下面我提到了我用来从 Firebase 服务获取的代码。

 this.firestore.getTicketList().subscribe(list => {
this.ticketList = list.map(item => {
return { id:item.payload.doc.id,
...item.payload.doc.data()}
})
console.log(this.ticketList);
});

谢谢

已编辑

enter image description here enter image description here

最佳答案

您可以通过传递Date对象来查询数据/时间戳字段。例如,现在获取之前的所有项目:

ref
.where('status', '==', "active")
.where("paid","==","false")
.where("myTimeStamp","<", new Date())
.orderBy("myTimeStamp")

关于node.js - 我们如何使用 Angular 按时间戳数据类型对 Firebase Firestore 数据进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54061164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com