0

I'm doing a really basic SPA application using nodejs, expressjs and mongodb and i'm getting an MissingSchemaError when i'm trying to run the application. It seems my db schema is not detected properly. I thought it was a typo but its not i'm new to node js and mongodb so a littler help will be appreciated.

monitoring.model.js

const mongoose = require('mongoose');

var monitoringSchema = new mongoose.Schema({
techName: {
    type: String
},
Customer: {
    type: String
},
Description: {
    type: String
}

});

mongoose.model('monitoring', monitoringSchema);

monitoringController.js

const  express = require('express');
var router = express.Router();
const mongoose = require('mongoose');
const monitoring = mongoose.model('monitoring');


router.get('/', (req, res) => {
res.render("monitoring/addOrEdit", {
    viewTitle : "Insert Problem"
});
});

 router.post('/',(req, res) => {

 console.log(req.body);
 });

 module.exports = router;
Joel D
  • 39
  • 7
  • Please check. The below Link can be helpful https://stackoverflow.com/questions/20832126/missingschemaerror-schema-hasnt-been-registered-for-model-user – Mohinuddin Luhar Sep 19 '19 at 12:28

2 Answers2

0

Try

export default mongoose.model('monitoring', monitoringSchema);

instead of

mongoose.model('monitoring', monitoringSchema);

You can have more informations about export default here

BillalZ
  • 1
  • 1
0

You can try an export model in a schema. And module export in the controller.

const mongoose = require('mongoose');

var monitoringSchema = new mongoose.Schema({
techName: {
    type: String
},
Customer: {
    type: String
},
Description: {
    type: String
}

});
export default model('Project', ProjectSchema);


const  express = require('express');
var router = express.Router();
const mongoose = require('mongoose');
const monitoringModel = require("../models/monitoring.model");
let monitoringController = {};


router.get('/', (req, res) => {
res.render("monitoring/addOrEdit", {
    viewTitle : "Insert Problem"
});
});

 router.post('/',(req, res) => {

 console.log(req.body);
 });

 module.exports = monitoringController;
Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43