引用错误:数字未在 MEAN 中定义



我正在 MEAN 中创建 CRUD 操作,我已经创建了 dataScehema.js 文件到定义的模型

var mongoose = require('mongoose');
var countrySchema = mongoose.Schema({
      name: { type: number },
      country: { type: number }    
});

module.exports = mongoose.model('country', countrySchema);

在我的索引中.js定义节点js服务器代码

var http = require('http');
var express = require('express');
var port = process.env.PORT || 8080;
var app = express();
var appRoutes = require('./routes/appRoute'); 
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var model = require('./model/dataSchema');
mongoose.connect('mongodb://localhost/meanDb')
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/',appRoutes);
http.createServer(app).listen(port);
console.log('Backend is running on port:',port);

我将为 route appRoute 创建的第三个文件.js,

var express = require('express');
var router = express.Router();
var Country = require('../model/dataSchema');
router.post('/create', (req, res, next) => {
   var newCountry = new Country({
       name: req.body.name,
       capital: req.body.capital
   });
   newCountry.save((err, country) => {
      if (err)
          res.status(500).json({ msg: err });
          res.status(200).json({msg: country});
    })
});

所以任何人,请帮助我。

架构类型应为数字而不是数字

var countrySchema = mongoose.Schema({
      name: { type: Number },
      country: { type: Number }    
});

相关内容

  • 没有找到相关文章