【发布时间】:2016-11-02 14:17:58
【问题描述】:
我正在尝试找出这种嵌套排序,但我所做的一切都行不通。
这是我尝试订购的数据结构示例:
{
"-KV_Lrm_93Agm8kAuXql": {
"body": {
"Acceleration": "0.0",
"Altitude": "11",
"Battery": "12.7",
"Date": "2016/09/10",
"order": 1,
"time": "2016-10-19T20:26:32Z"
}
},
"-KV_LuTfJ9VrKRHoRWuw": {
"body": {
"Acceleration": "0.0",
"Altitude": "11",
"Battery": "12.7",
"Date": "2016/09/10",
"order": 5,
"time": "2016-10-21T20:26:32Z"
}
},
"-KV_Lx9VABuEB8D3I-i1": {
"body": {
"Acceleration": "0.0",
"Altitude": "11",
"Battery": "12.7",
"Date": "2016/09/10",
"order": 2,
"time": "2016-10-01T20:26:32Z"
}
},
"-KV_LzQOM3rHEKQuwyHQ": {
"body": {
"Acceleration": "0.0",
"Altitude": "11",
"Battery": "12.7",
"Date": "2016/09/10",
"order": 10,
"time": "2016-09-01T20:26:32Z"
}
},
"-KV_M0fdznAbKanHoY91": {
"body": {
"Acceleration": "0.0",
"Altitude": "11",
"Battery": "12.7",
"Date": "2016/09/10",
"order": 6,
"time": "2016-09-20T20:26:32Z"
}
}
}
根据 firebase 文档 (https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html),您可以执行“深度路径查询”。就我而言,如果我想按 order 排序,我应该可以这样做:
.orderByChild("body/order")
但这无济于事。它对结果的排序没有影响。我也尝试过按日期和时间订购,但都不起作用。这是我的完整节点功能。这将返回结果,只是未排序:
app.get('/api/xirgo-data', function(req, res)
{
var ref = db.ref("xirgo");
ref
.orderByChild("body/order")
.on("value", function(snap) {
return res.json(snap.val());
});
});
谢谢!
【问题讨论】:
标签: node.js firebase firebase-realtime-database