Sye*_*l A 1 nosql firebase google-cloud-firestore
所以我在Firebase Cloud 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"
}
]
Run Code Online (Sandbox Code Playgroud)
我想用时间戳查询数据并获取属于特定月份或日期的数据。
例如,如果我单击日历中的特定月份(例如3月),则结果中只需要该特定月份的数据。我怎样才能做到这一点?
我已使用保存日期
firebase.firestore.FieldValue.serverTimestamp()
在此先感谢您的帮助。
编辑:
这就是我形成查询的方式
var spendsRef = this.db.collection('spend', ref => ref.where("timestamp", ">", "12-12-2017"));
this.items = spendsRef.valueChanges();
Run Code Online (Sandbox Code Playgroud)
但是它仍然返回我数据库中的所有数据
答:
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();
Run Code Online (Sandbox Code Playgroud)
使用两个相对运算符,可以确定查询返回的文档的精确范围:
ref.where("timestamp", ">=", "2017-11").where("timestamp", "<", "2017-12")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2232 次 |
| 最近记录: |