ReferenceError: number is not defined in MEAN

ReferenceError: number is not defined in 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);

并在我的index.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);

我将为路线创建的第三个文件 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 }    
});