Mongoose finds why undefined is returned

exports.getAllStudent = function (req, res) {
    //
    var rows = url.parse(req.url, true).query.rows;
    var page = url.parse(req.url, true).query.page;
    var sidx = url.parse(req.url, true).query.sidx;
    var sord = url.parse(req.url, true).query.sord;

    var sordNumber = sord == "asc" ? 1 : -1;

    //
    Student.count({}, function (err, count) {
        //
        console.log(count)
        var total = Math.ceil(count / rows);
        console.log(total)
      
        var sortobj = {};
        //
        sortobj[sidx] = sordNumber;
        //
        //recordspagetotalrowsjqGrid
        //     http://blog.mn886.net/jqGrid/   demo
        //API:http://blog.mn886.net/jqGrid/JSONData
        /* Student.find({},function (err,results) {
             //console.log(results);
             res.json({"records" : count, "page" : page, "total" : total , "rows" : results});
         });*/
 
      
        /*.sort(sortobj)*/
        Student.find({}).limit(rows).skip(rows * (page - 1)).exec(function (err, results) {
            console.log(rows,page);
            console.log(results)
            res.json({"records": count, "page": page, "total": total, "rows": results});
        });
    });
};
Mar.28,2021

exec (function (err,results in the second find) {console.log (err)} you can know that there is a problem with the type of limit (rows). Add var rows = url.parse (req.url, true) .query.rows; = > var rows = parseInt (url.parse (req.url, true) .query.rows) in the declaration; then


let the problem owner know the reason at last?

Menu