mongodb错误$ skip的参数不能为负

时间:2019-08-14 15:33:10

标签: node.js mongodb mongoose

我收到此错误:

  

$ skip的参数不能为负     errmsg:“ $ skip的参数不能为负”,     代码:15956,     codeName:“ Location15956”,     名称:“ MongoError”,     [Symbol(mongoErrorContextSymbol)]:{}}

这是我的代码

exports.postLeads = (req, res, next) => {
    console.log(req.body,"post")

    paging.pageIndex = parseInt(req.body.changepage)

    if (req.body.btnAdd === 'add') {
        res.redirect('/employees/dashboard/leads')

       /*
mongoose.Lead.findByIdAndUpdate(mongoose.ObjectId(req.body.leadID), { now_status: req.body.status })
        .then(add => { 
            console.log(add)

            const leadProcess = new LeadProcess({
                status: req.body.status,
                userID : parseInt(req.body.userID),
                leadID: mongoose.ObjectId(req.body.leadID),
                msg: req.body.msg
            })

            leadProcess.save()

            setTimeout(() => {
                res.redirect('/employees/dashboard/leads')

            }, 1500);
        })
        .catch(err => { console.log(err) } )
*/
    } else {
        getDataFromDB(req,res,next)
    }
}

const getDataFromDB  = (req,res,next) => {
    mongoose.Lead.aggregate([
        {  $match: {userID: global.loginEmployee.userID}},
        {  $lookup: {
                from: "leadprocesses",
                localField: "_id",
                foreignField: "lead_id",
                as: "thisleadprocesses"
            }
        },
        { $match: {"thisleadprocesses": {$ne: []} } },
        { $sort: {"thisleadprocesses.last_date_modified": -1} },
    ])
    .skip(paging.pageIndex * 10)
    .limit(paging.itemPerPage + 1)
    .then(
        results =>  {
        console.log(results)

        setPageData(results)

        renderLeadsTable(req,res,next,results)
      }
    ).catch(err=> {console.log(err)})
}

我想通过邮寄到服务器来更新数据库

0 个答案:

没有答案