私はdbに新しい投稿を挿入しようとするとmongodbで基本的な処理を行いますが、Testは関数ではないので投稿者のメッセージを受け取ります。モデルは郵便配達員の関数エラーではありません
ルータの機能は次のとおりです。
router.route('/createtests').post(function (req, res, next) {
var Test = new Test(req.body);
postTest(Test, function (data) {
res.json({'message': 'The test created sucessfully'});
});
});
var postTest = function(test, cb){
Test.save(function(err,data){
cb(data);
});
};
私のスキーマは次のとおりです。
var TestSchema = common.Schema({
title : String,
testCreator : String,
datePosted : {
type: Date,
default: Date.now
},
totalQuestions : Number,
totalTime : Number,
numberOfPeopleTaking : Number,
dateOfTest : Date,
marksPerQuestions : Number,
imageUrl : String,
testType : String,
});
var Test = common.conn.model('Test', TestSchema);
console.log(typeof Test);// logging as function
console.log(Test);// logging full model with schema
module.exports = Test;
Iamの応答を得るあなたの機能postTest
で
{
"message": "Test is not a function",
"error": {}
}
はmongooseと共通ですか? – winter
はい。それはマングースの目的です。スキーマ:require( 'mongoose')。スキーマは共通のプロパティです。 –
'var test = common.conn.model( 'Test'、TestSchema);' – winter