I'm developing an app with node.js, mongodb, mongoose and I get an error when I added these files.
This is the "model.js" file:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var RequestDiffSchema = new Schema({
id: {
type: Number,
unique: true,
required:true
},
solicitudId: {
type: Number,
required: true
},
errors: {
type: String,
required:true
}
}, { collection: 'requestdiff' });
module.exports = mongoose.model('RequestDiff', RequestDiffSchema);
And this is the "controller.js" file:
'use strict';
var mongoose = require('mongoose'),
RequestDiff = mongoose.model('RequestDiff'),
q = require('q'),
Promise = q.Promise;
var RequestDiffController = {
// Aquí van las funciones
};
module.exports = RequestDiffController;
I get an error when I raise the server and I can not fix it, did something wrong? some mistake? or am I missing a step?
The error that throws me by console is:
Error initializing middleware
MissingSchemaError: Schema hasn't been registered for model "RequestDiff".
Use mongoose.model(name, schema)
at Mongoose.model (/Documentos/api/backend.server/node_modules/mongoose/lib/index.js:349:13)
at Object.<anonymous> (Documentos/api/backend.server/api/controllers/requests-diff.js:7:28)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
Is it because the model does not take me well? The routes are correct and I do not see the fault ...