Alright, so I'm building an application based in Node.js and I am using mongoose to handle my connection to mongodb. I have an endpoint that is such:
getTestStream : function(req, res, conditions, callback) {
Activity.find()
.limit(1000)
.run(function(err, activities) {
if (err){
util.sendError(req, res, "Query Error", err);
} else if (activities) {
res.send(activities);
} else {
util.send('nope');
}
});
}
For some reason this call takes 700ms+ to complete. The same call without even applying a limit made from mongodb shell returns in about 4ms. It seems like such a simple query, so what's slowing it down so much? I'm guessing I've missed something obvious in configuration somewhere, but I have no idea.
Thanks to anyone who can help on this.
Other info:
[email protected]
[email protected]
[email protected]
After experimenting for a while, I've found several contributions to slowness, hopefully this helps anyone with a similar issue:
Using these techniques I can now process 4000 records in less time than I was processing 1000 before. Thanks for anyone who commented, and special thanks to Gates VP for pointing out that mongoose wasn't really a good fit for this kind of call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With