node.js - mongoose aggregate keeps node server blocked -


i have couple hundred thousand documents in collection, each timestamp field.

i want count number of records respect each day last month.

i'm running mongoose aggregate command unfortunately taking long time expecting.

following aggregate function:

function dailystats() {     var lastmonth = new date();     lastmonth.setmonth(lastmonth.getmonth() - 1);      mymodel.aggregate(         {             $match: {timestamp: {$gte: lastmonth}}         },         {             $group: {                 // data count grouped date                 _id: {$datetostring: {format: "%y-%m-%d", date: "$timestamp"}},                 count: {$sum: 1}             }         },         {$sort: {"_id": 1}},         function (err, docs)         {             console.log(docs);         }); } 

now, whole point of callbacks non-blocking code. however, when function executed, takes around 20-25 seconds. whole time, node application doesn't respond other apis!

first thought cpu gets busy not responding else. had small node app run along it, works fine!
don't understand why application not respond other requests till mongodb driver returns result.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -