Req.params.id被另一个值覆盖

时间:2018-04-20 22:04:26

标签: node.js regex express routes

请帮助,我无法弄清楚为什么我的req.params.qcerrorId被app.js覆盖了......我看到我在console.log时填充了id和app.js。代码如下。提前谢谢。

//Show Single Route
router.get("/employee/:id/qcerror/:qcerrorId", isLoggedin, function(req, res){
    console.log(req.params['qcerrorId']);
    QcError.findById(req.params.qcerrorId, function(err, foundQcError){
        if(err){
            console.log(err);
        } else {
    res.render('qcerrors/show', {employee: req.params.id, qcerror: foundQcError});
        }
    });
});

前两行的console.log出错。

5ad924324d0db10fe02ab4ad
app.js
{ CastError: Cast to ObjectId failed for value "app.js" at path "_id" for model "QcError"
    at MongooseError.CastError (/home/ubuntu/workspace/node_modules/mongoose/lib/error/cast.js:27:11)
    at ObjectId.cast (/home/ubuntu/workspace/node_modules/mongoose/lib/schema/objectid.js:158:13)
    at ObjectId.SchemaType.applySetters (/home/ubuntu/workspace/node_modules/mongoose/lib/schematype.js:724:12)
    at ObjectId.SchemaType._castForQuery (/home/ubuntu/workspace/node_modules/mongoose/lib/schematype.js:1095:15)
    at ObjectId.castForQuery (/home/ubuntu/workspace/node_modules/mongoose/lib/schema/objectid.js:198:15)
    at ObjectId.SchemaType.castForQueryWrapper (/home/ubuntu/workspace/node_modules/mongoose/lib/schematype.js:1064:15)
    at cast (/home/ubuntu/workspace/node_modules/mongoose/lib/cast.js:300:32)
    at Query.cast (/home/ubuntu/workspace/node_modules/mongoose/lib/query.js:3210:12)
    at Query._castConditions (/home/ubuntu/workspace/node_modules/mongoose/lib/query.js:1280:10)
    at Query._findOne (/home/ubuntu/workspace/node_modules/mongoose/lib/query.js:1496:8)
    at process.nextTick (/home/ubuntu/workspace/node_modules/kareem/index.js:311:33)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
  message: 'Cast to ObjectId failed for value "app.js" at path "_id" for model "QcError"',
  name: 'CastError',
  stringValue: '"app.js"',
  kind: 'ObjectId',
  value: 'app.js',

它正在返回" app.js"在" qcerrorId"之后,为什么?

0 个答案:

没有答案