我需要的帮助,以查询与日期范围长收集。请参阅下面的示例文档。我想用日期范围查询startTime字段。


发布于 2017-10-30 06:32:45
由于我在Cloud Firestore上将dueDate字段存储为"timestamp“(而不是string或number),因此我这样做是为了获得到期日为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 ()对象存储在firebase中。例如:this.doc.dueDate = new Date('2017-12-25')
发布于 2017-10-29 22:45:32
您可以将datetime对象存储为Unix time (自1970年1月1日以来的秒数)。然后您可以像这样简单地使用where select:
collectionRef.where("startTime", ">=", "1506816000").where("startTime", "<=", "1507593600")
顺便说一句--要在你的应用程序中将日期时间转换为Unix时间,你可以使用优秀的(现在已经被废弃的)库moment (如果你正在用js或node构建一些东西)。
发布于 2019-04-27 06:27:57
var startfulldate = admin.firestore.Timestamp.fromDate(new Date(1556062581000));
db.collection('mycollection')
.where('start_time', '<=', startfulldate)
.get()
.then(snapshot => {
var jsonvalue: any[] = [];
snapshot.forEach(docs => {
jsonvalue.push(docs.data())
})
res.send(jsonvalue);
return;
}).catch( error => {
res.status(500).send(error)
});https://stackoverflow.com/questions/47000854
复制相似问题