node.js - 我们如何使用 Angular 按 TimeStamp 数据类型对 Firebase Firestore 数据进行排序?
问题描述
我正在使用 Ticket Posting Web 应用程序,我只会显示那些有效且在 24 小时内(从现在开始)记录内的票。
我正在使用Firebase Cloud Firestore和Angular 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 时间戳类型。
只想显示那些处于活动状态且当前还有时间预订的记录。
Beow 我提到了我用来从 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);
});
谢谢
已编辑
解决方案
您可以通过传递Date
对象来查询数据/时间戳字段。因此,例如现在之前获取所有项目:
ref
.where('status', '==', "active")
.where("paid","==","false")
.where("myTimeStamp","<", new Date())
.orderBy("myTimeStamp")
推荐阅读
- sql - 一对多对多关系,使用复合键
- nativescript - 删除的钩子文件夹
- r - 无法安装 TTR(tseries)R 3.3.3(在 debian 拉伸上)
- android - 如何为 midi/audio 获得精确的时钟
- django - 如何在内存中创建文件(不是上传的文件)并通过 Django default_storage 保存到 FileField?
- bash - tmux中的电力线不在状态栏左侧显示段
- java - 使用带有多个分隔符的正则表达式(Java / Kotlin)拆分文本
- javascript - 是否可以将表单输入到另一个 html 表单中
- bash - .bashrc 中的别名失败 vs 命令行成功
- javascript - 如何从我的 firebase 用户列表中获取随机用户?