0

我一直在处理下面的路由文件。但是,它本质上是一个照片应用程序,我可以在其中将数据存储在 MondoDB 中。但是,当我运行下面的代码时,终端一直说意外令牌 .then。我在这里错过了什么吗?

var express = require('express');
var router = express.Router();
var app = express();
var multer = require('multer');
var upload = multer({dest: 'public/images/'});
var Photo = require ('../models/travelModels');

router.get('/', (req, res, next)=>{
    Photo.find({})
      .then((photos) =>{
       res.render('lists', {
       list: photos
     });
  });
});

router.post('/', upload.single('image'), (req, res, next)=>{

   var path = "/static/images" + req.file.filename;
   var item  = {
      destination: req.body.destination,
      description: req.body.description,
      imageurl: path,
      mimetype: req.file.mimetype,
      filename: req.file.filename
    }

  // save photo in database
    var entry = new Photo (item);
    entry.save();
       .then(()=>{
        res.redirect('/mylist')
      });
    // or catch error
       .catch((err)=>{
          if (err){
            console.log(err);
         }
      });
});


module.exports = router;
4

1 回答 1

3

您需要删除分号,之前then和之前catch

var entry = new Photo (item);
entry.save()
 .then(()=>{
  res.redirect('/mylist')
 })
 .catch((err)=>{
    if (err){
      console.log(err);
    }
 });

于 2018-03-16T16:15:36.653 回答