Cri*_*s69 1 sails.js waterline
什么是最好的解决方案,以查找只有一条记录的 Waterline - Sails 查询来搜索给定日期中 room2 的最后插入价格?
ID PRICE START STOP ROOM createdAt updatedAt
-------------------------------------------------------------------------
85 750.00 2016-01-01 2017-12-31 room1 2016-02-25 10:09:47 2016-02-25 10:09:47
86 590.00 2016-01-01 2017-12-31 room2 2016-02-25 10:09:55 2016-02-25 10:09:55
90 410.00 2016-02-25 2016-02-27 room2 2016-02-25 16:46:08 2016-02-25 16:46:08
91 310.00 2016-01-26 2016-04-28 room2 2016-02-26 09:35:26 2016-02-26 09:35:26
Run Code Online (Sandbox Code Playgroud)
做这些我得到错误的结果:
var where = {"start":{"<=":"2016-02-25T23:00:00.000Z"},"end":{">=":"2016-02-25T23:00:00.000Z"},"room":"room2"}
PriceHistory.find(where).max('createdAt').exec(function(err, prices){
res.json(prices);
});
Run Code Online (Sandbox Code Playgroud)
如何使用 createdAt 降序排序并限制为一条记录?
PriceHistory.find(where)
.sort('createdAt DESC')
.limit(1)
.exec(function(err, prices){
res.json(prices); // should return one record (last one)
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2538 次 |
最近记录: |