我正在尝试使用 Mongoose 将架构直接保存在数据库中。这是保存在 MongoDB 中的代码 (schema.js):
var mongoose = require('mongoose');
var Mixed = mongoose.Schema.Types.Mixed;
var modelSchema = mongoose.Schema({
schemaname:String,
object : Mixed
})
var Model = mongoose.model('Model',modelSchema);
exports.createModel = function(model){
var model_to_create = new Model(model);
console.log("creating a schema..." + model)
model_to_create.save(function(err,data){
console.log("Saving a schema...")
if(err){
return "model creation failed";
}else {
return "model creation success";
}
});
}
我正在使用以下代码创建架构:
var schema = require('../schemas/schema');
var status = schema.createModel({
"username": String,
"firstname": String,
"lastname": String,
"description": String,
"education": String
})
由于某种原因,架构没有保存在数据库中。当我打印 "status" 时,我得到 "undefined"
谁能帮我解决这个问题?