throw new mongoose.Error.MissingSchemaError(name);
MissingSchemaError: Схема не была зарегистрирована для модели "Comapign". Используйте mongoose.model (имя, схема) в новой ошибке MissingSchemaError (C: \ Users \ Zakaria5 \ Desktop \ StageTechnique2019 \ zen-networks-backend \ node_modules \ mongoose \ lib \ error \ missingSchema.js: 22: 11)
здесь есть compaign.model.js
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
var compaignSchema = new mongoose.Schema({
requestid : {
type : Number , required : true
},
requestname : {
type:String
},
saltSecret : {
type : String
}
});
// Events
compaignSchema.pre('save', function (next) {
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(this.requestid, salt, (err, hash) => {
this.requestid = hash;
this.saltSecret = salt;
next();
});
});
});
mongoose.model('Compaign',compaignSchema);
}
compaign.controller.js
const mongoose = require('mongoose');
const Compaign = mongoose.model('Comapign');
module.exports.register = (req,res,next) =>{
var compaign = new compaign();
compaign.requestid = req.body.requestid;
compaign.requestname = req.body.requestname;
compaign.save((err,doc) =>{
if (!err)
res.send(doc);
return next(err);
});
}
app.js
require('./config/config');
require('./models/db');
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const rtsIndex = require('./routes/index.router');
var app = express();
//middleware
app.use(bodyParser.json());
app.use(cors());
app.use('/api',rtsIndex);
// start server
app.listen(process.env.PORT,() => console.log(`Server started at port : ${process.env.PORT}`));