因此,我在firebase云firestore中有如下记录:
[
{
"category":"drinks",
"expensetype":"card",
"id":"5c673c4d-0a7f-9bb4-75e6-e71c47aa8d1d",
"name":"JJ",
"note":"YY",
"price":57,
"timestamp":"2017-11-30T22:44:43+05:30"
},
{
"category":"drinks",
"expensetype":"card",
"id":"85731878-eaed-2740-6802-e35e7758270b",
"name":"VV",
"note":"TTT",
"price":40,
"timestamp":"2017-12-30T22:41:13+05:30"
}
]我想查询带有时间戳的数据,并获取属于特定月份或日期的数据。
例如,如果我单击日历中的某个特定月份(例如3月),我只想在结果中显示该特定月份的数据。我该怎么做呢?
我已经使用firebase.firestore.FieldValue.serverTimestamp()保存了日期
提前感谢您的帮助。
编辑:
这就是我形成查询的方式
var spendsRef = this.db.collection('spend', ref => ref.where("timestamp", ">", "12-12-2017"));
this.items = spendsRef.valueChanges();但它仍然会返回数据库中的所有数据
答案:
var todayDate = new Date("Tue Jan 02 2018 00:00:00 GMT+0530 (IST)") // Any date in string
var spendsRef = this.db.collection('spend', ref => ref.where("timestamp", ">", todayDate));
this.items = spendsRef.valueChanges();发布于 2018-01-02 23:26:25
使用两个relative运算符,可以确定查询返回的文档的精确范围:
ref.where("timestamp", ">=", "2017-11").where("timestamp", "<", "2017-12")发布于 2018-01-02 19:20:17
这就是android的方式
Query query = mFirestore.collection("rootcollection").whereEqualTo("month", 3);
您可以进一步按时间戳对结果进行排序
Query query = mFirestore.collection("rootcollection")
.orderBy("timestamp", Query.Direction.DESCENDING)
.whereEqualTo("month", 3);发布于 2021-11-29 05:41:07
我正在使用node.js,并将一个参数存储为new Date(new Date().toUTCString())。
现在,我获取相同的数据,对其进行一些处理,并在where查询中使用参数new Date(<param received in fetch>)来获取多条记录中的相同记录。
谢谢你@Syed Sehu Mujammil A,你的回答起作用了。
https://stackoverflow.com/questions/48059941
复制相似问题