{
"places": {
"<push-key>": {
"name": "Company X"
},
"<push-key>": {
"name": "Restaurant Y"
}
}
"stamps": {
"<push-key>": {
"value": 0,
"date": 1487344650456
}
},
"placeStamps": {
"<place-push-key>": {
"<stamp-push-key-1>": true,
"<stamp-push-key-2>": true,
"<stamp-push-key-3>": true
}
}
}
我们是Firebase的新手,我们想知道是否有办法按日期对邮票(数据库中的节点)进行排序。我们的流程如下:
有没有办法按例如'date'或'value'对这些对象进行排序/过滤?我们无法做客户端,因为我们正在讨论数以百万计的邮票。
答案 0 :(得分:0)
自24小时前查询邮票:
var ref = firebase.database.ref("stamps");
var now = Date.now();
var yesterday = now - 24 * 60 * 60 * 1000;
var query = ref.orderByChild("Date").startAt(yesterday);
query.on("child_added", function(snapshot) {
console.log(snapshot.key);
});
如果您想按时间戳检索某个地方的图章,您有两种选择:
为每个地方的戳记键添加时间戳:
placeStamps": {
"<place-push-key>": {
"<stamp-push-key-1>": 1487344650456,
"<stamp-push-key-2>": 1487344650457,
"<stamp-push-key-3>": 1487344650458
}
}
现在你可以通过时间戳获得一个地方的邮票:
var ref = firebase.database.ref("placeStamps").child("<place-push-key>");
var now = Date.now();
var yesterday = now - 24 * 60 * 60 * 1000;
var query = ref.orderByValue().startAt(yesterday);