diff --git a/handlers/dataHandlers.js b/handlers/dataHandlers.js index d89b280..09dd129 100644 --- a/handlers/dataHandlers.js +++ b/handlers/dataHandlers.js @@ -352,13 +352,20 @@ Mark.pointList = function(req, res, next) { var query = req.query; delete query.token; var points = []; - - mongoDB.find("camic", 'mark', query, { x: 1, y: 1, _id: 0 }).forEach((doc) => { - points.push([doc.x, doc.y]); - }).then(() => { - req.data = { points: points }; - next(); - }).catch((e) => next(e)); + + var cursor = mongoDB.find("camic", 'mark', query, { x: 1, y: 1, _id: 0 }); + + cursor.each((err, doc) => { + if (err) { + return next(err); + } + if (doc) { + points.push([doc.x, doc.y]); + } else { + req.data = { points: points }; + next(); + } + }); };