关于此错误的堆栈溢出问题很多。但是他们的解决方案似乎对我不起作用。所以我终于决定发表我自己的问题。 (这可能与我缺乏对javascript / node / mongoose的了解有关)
我的模块是-
shared_conv1 = Conv1D(filters=8, kernel_size=3, activation='relu')
for i in range(4):
inputs = Input(shape=(n_timesteps,1))
conv1 = shared_conv1(inputs)
conv2 = Conv1D(filters=16, kernel_size=3, activation='relu')(conv1)
conv3 = Conv1D(filters=32, kernel_size=3, activation='relu')(conv2)
flat = Flatten()(conv3)
in_layers.append(inputs)
out_layers.append(flat)
merged = concatenate(out_layers)
# interpretation
dense1 = Dense(200, activation='relu')(merged)
dense2 = Dense(100, activation='relu')(dense1)
outputs_1 = Dense(10)(dense2)
outputs_2 = Dense(10)(dense2)
outputs_3 = Dense(10)(dense2)
outputs_4 = Dense(10)(dense2)
我的控制器有这个-
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
var OptionSchema = new Schema({
option_text: {type: String, required: true},
is_correct: {type: Boolean, required: true, default: false}
});
var QuestionSchema = new Schema({
question_text: {type: String, required: true},
subText: {type: String, required: true},
type: {type: String, required: true},
difficulty: {type: String, required: true, default: 'Easy'},
status: {type: String, required: true, default: 'Private'},
options_required: {type: Boolean, required: true, default: false},
explanation: {type: [String], required: true},
created_by: {type: String, required: true, default: 'Anonymous'},
created_at: {type: Date, required: true, default: Date.now()},
options: [OptionSchema]
});
// Export the model
module.exports.Question = QuestionSchema;
module.exports.Option = OptionSchema;
我能找到的最接近的问题在此链接上- Mongoose TypeError: User is not a constructor
但是答案没有用。
_ / \ _
答案 0 :(得分:0)
我认为您需要按照以下步骤做些事情:
module.exports.Question = mongoose.model('Question', QuestionSchema);
答案 1 :(得分:0)
您正在尝试创建模式的新实例,而不是模型。只有模型具有构造函数,而没有架构。这是由于您没有导出模型而是导出了架构。需要这样做:
// Export the model
module.exports.Question = mongoose.model('Question', QuestionSchema);
module.exports.Option = mongoose.model('Option', OptionSchema);
然后,您可以在控制器中导入模型:
var Question = require('./models/question');
var Option = require('./models/option');
假设模型位于models
文件夹中。