I can't figure out why I keep experiencing 504 Gateway timeouts.
app.get("/api/exercise/log", function(req,res) {
let userId = req.query.userId;
let from = req.query.from;
let to = req.query.to;
let limit = req.query.limit;
console.log("limit1 " + limit);
User.findById(userId).exec(function (err,data) {
console.log("limit2 " + limit);
if (err) return err;
Exercise.find({userId: userId}).limit(limit).exec(function (err2,data2) {
console.log("limit3 " + limit);
if (err2) return err2;
let logArr = [];
logArr.push(data2);
let total = logArr[0].length;
let answer = Object.assign({}, data._doc, {log: logArr}, {total: total});
res.json(answer);
})
})
})
My url ends with log?userId=555&limit=2. Despite all console logs (limit1, limit2, limit3) correctly printing '2', I am still encountering only timeouts. However, when manually setting the limit value to 2 as shown below:
Exercise.find({userId: userId}).limit(2).exec(function (err2,data2) {
everything seems to work fine and I receive the accurate number of results. What could be causing this inconsistency?