如何获得最近一个小时的所有用户?

时间:2019-02-05 06:43:41

标签: mongoose

我有一次访问报告。 我需要获取最近一个小时的用户列表(ssoid)。 有记录示例:

{"_id":{"$oid":"5c58af318c5faf0f20775db6"},"ssoid":"650ae77a-ffce-475d-a930-c7e345e0658c","ts":{"$date":{"$numberLong":"1499763594000"}},"grp":"guis_-47","type":"formcontroller","subtype":"send","url":"https://www.mos.ru/pgu/ru/application/guis/-47/#step_1","orgid":"guis","formid":"-47","code":"MPGU","ltpa":"","sudirresponse":"","ymdh":"2017-07-11-09","__v":{"$numberInt":"0"}}

 {"_id":{"$oid":"5c58af318c5faf0f20775db7"},"ssoid":"aeadac26-3e19-438b-8e4a-a1ae754bbe41","ts":{"$date":{"$numberLong":"1499763600000"}},"grp":"guis-47","type":"bill","subtype":"prepare","url":"","orgid":"","formid":"","code":"","ltpa":"","sudirresponse":"","ymdh":"2017-07-11-09","__v":{"$numberInt":"0"}}

请帮助获得正确的猫鼬聚合。 我的代码不正确

 let reportSchema = new Schema({
 ssoid: {type: String},
 ts: {type: Date},
 grp: {type: String},
 type: {type: String},
 subtype: {type: String},
 url: {type: String},
 orgid: {type: String},
 formid: {type: String},
 code: {type: String},
 ltpa: {type: String},
 sudirresponse: {type: String},
 ymdh: {type: String}
 });

 let Report = mongoose.model('Report', reportSchema);

 Report.aggregate([
     { $sort: { ts: 1 } },
     { $group: {_id:'$ssoid', count:{$sum:1}, lastSalesDate: { $last: 
 "$ts" }}},
 ]).
 then(function (res) {
  console.log(res); // [ { maxBalance: 98000 } ]
 });

0 个答案:

没有答案