模式尚未为模型“类别"注册.使用mongoose.model(名称,模式) [英] Schema hasn't been registered for model "categories". Use mongoose.model(name, schema)
本文介绍了模式尚未为模型“类别"注册.使用mongoose.model(名称,模式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我通过邮递员在控制器中调用我的函数时,它工作正常并且得到了结果,但是当我为相同的函数编写测试用例时,它说的是错误
When i called my function in controller through postman,it worked fine and i got results but when i wrote a test case for the same function it is saying the error as
MissingSchemaError: Schema hasn't been registered for model "categories".
Use mongoose.model(name, schema)
我对这些完全感到困惑,因为一个功能良好的功能如何在测试用例中出错.任何人都可以建议帮助. 我的test.js,
I was completely confused about these because how come a function that is working well go wrong with test case.Can any one suggest help please. My test.js,
var server = require('../modules/categories/model/categories.server.model');
var chai = require('chai');
var chaiHttp = require('chai-http');
var should = chai.should();
var mongoose = require('mongoose');
chai.use(chaiHttp);
describe('Blobs', function() {
it('should list ALL blobs on /getcategories GET');
});
it('should list ALL categories on /getcategories', function(done) {
chai.request(server)
.get('getcategories')
.end(function(err, res){
res.should.have.status(200);
done();
});
});
我的路线,
*/
var categories = require('../categories/controller/categories.server.controller');
var model = require('../categories/model/categories.server.model');
var passport = require('passport');
module.exports = function (app) {
// User Routes
app.use(function (req, res, next) {
// Setting up the users password api
app.route('/api/auth/insertcategory').post(categories.insertcategory);
app.route('/api/auth/getcategoriesbycreatedid/:id').get(categories.getcategoriesbycreatedid);
app.route('/api/auth/getcategories').get(categories.getcategories);
});
有人可以建议帮助吗?
推荐答案
当您在解释之前尝试在任何地方使用
model
时,通常会出现此问题.
This issue normally raise when you try to use your
model
in anywhere before interpreting it.
尝试在所有controllers and routes
赞
var model = require('../categories/model/categories.server.model');
var categories = require('../categories/controller/categories.server.controller');
var passport = require('passport');
希望这会对您有所帮助.
Hope this will help you.
这篇关于模式尚未为模型“类别"注册.使用mongoose.model(名称,模式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文