Как получить всех пользователей за последний час? - PullRequest
0 голосов
/ 05 февраля 2019

У меня есть отчет о посещениях.Мне нужно получить список пользователей (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 } ]
 });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...