MissingSchemaError:尚未为模型“博客”注册架构

时间:2019-02-27 08:58:30

标签: mongodb express mongoose

我遇到了卡住的错误,我是mongodb,expressjs的初学者

我的Index.js:

 const mongoose= require('mongoose')
 let modelspath ='./models'
fs.readdirSync(modelspath).forEach(function(file){
    if(~file.indexOf('.js')) 
    console.log(file)
    require(modelspath +'/' + file) //if block checks weather file ending with .js ext
}) 
我的控制器文件

const BlogModel = mongoose.model('Blog')
let testRoute = (req, res) => 
{
    console.log(req.params)
    res.send(req.params)
}

我的model.blog.js文件

const mongoose = require('mongoose')
const Schema = mongoose.Schema;
let blogSchema =new Schema(
    {
        blogId :{
            type: string,
            unique:true   
        },

mongoose.model('Blog',blogSchema);
我的路由文件

const express =require('express')
//here we can find routees logic path
const control =require('./../controllers/controller')
let setRouter =(app) =>{
//here we are getting our logics and assigning for a Http verbs (get,post,put,del)
 app.get('/test/route/:param1/:param2',control.testRoute)
 app.get('/example',control.example)
//  app.post('/hello', control.postmethod)
}
module.exports={
    setRouter:setRouter
}

有人可以帮助我解决这个错误

0 个答案:

没有答案