Query code:
Time ('timer1')
collection.count({}, function(err, count) {
collection.find({}, {
limit: num,
skip: (data.page - 1) * num
}).sort({
time: -1
}).toArray(function(err, list) {
mongoDb.close();
var page = {}
page["count"] = count
page["limitNum"] = num
callback(null, list, page)
Timeend ('timer1')
})
});
Above, this is the mongo time-consuming time I monitored under window again.
The following figure shows the time I spent under linux.
Why do the same query codes differ by almost 3 times? My data volume is only 67
I found the reason, because the account password is set. I think mongo will verify the account password every time I request it, which takes a long time and drops to about 30ms after removing it.