Answer the question
In order to leave comments, you need to log in
How to get a list of all users in the last hour from Mongo db?
There is a DB on mongo.
The scheme is this:
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}
});
{"_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 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);
});
Answer the question
In order to leave comments, you need to log in
"in the last hour" is "greater than the current time minus 3600 seconds"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question