Javascript 查询mongodb数据时在nodejs中获取错误?

Javascript 查询mongodb数据时在nodejs中获取错误?,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,我在nodejs控制台中遇到错误(更多说明请参见屏幕截图) 在matches.js中: const mongoose = require('mongoose'); let Schema = mongoose.Schema; const matchSchema = new Schema({ match_id:{ type:Number; <---- line 8 required:true; }, season:{

我在nodejs控制台中遇到错误(更多说明请参见屏幕截图)

在matches.js中:

const mongoose = require('mongoose');

let Schema = mongoose.Schema;

const matchSchema = new Schema({

    match_id:{
        type:Number;     <---- line 8
        required:true;
    },

    season:{
        type:Number;
        required:true;
    }

.....
.....
});

const matches = mongoose.model('matches', matchSchema);

module.exports = matches;

// Get matches
module.exports.getmatches = (callback, limit) => {
    matches.find(callback).limit(limit);
}
我制作了一个模型文件夹,其中包含matches.js。我正在尝试从mongodb访问数据,以及何时将其显示为API端点上的JSON数据,即
localhost://5000/home


这是一个基本的JavaScript对象声明错误。JSON对象应该如下所示

{
   match_id: {
     type: Number,    //see the comma there?
     required: true
   }
}
您使用的不是
,而是
将引发语法错误。用这个代替

const matchSchema = new Schema({
    match_id: {
        type:Number,
        required:true
    },
    season: {
        type:Number,
        required:true
    }
    .....
    .....
});

另外,您的
getmatches
函数需要将限制作为第二个参数传递,您还需要在代码中传递该限制

这是一个基本的JavaScript对象声明错误。JSON对象应该如下所示

{
   match_id: {
     type: Number,    //see the comma there?
     required: true
   }
}
您使用的不是
,而是
将引发语法错误。用这个代替

const matchSchema = new Schema({
    match_id: {
        type:Number,
        required:true
    },
    season: {
        type:Number,
        required:true
    }
    .....
    .....
});

另外,您的
getmatches
函数需要将限制作为第二个参数传递,您还需要在代码中传递该限制

在第8-9行,您必须用逗号替换分号(使其成为有效的json对象)@Brain doneerror@brain如果您给出简短的答案,我可以投票:)在第8-9行,您必须用逗号替换分号(使其成为有效的json对象)@脑力劳动仍然有用error@brain如果你能给我一个简短的答案,我可以投票:)