I am trying to save the schema directly in DB using Mongoose. Here is the code (schema.js) to save in MongoDB :
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";
}
});
}
I am creating a schema using the following piece of code :
var schema = require('../schemas/schema');
var status = schema.createModel({
"username": String,
"firstname": String,
"lastname": String,
"description": String,
"education": String
})
For some reason, the schema is not getting saved in the DB. When I print "status" , I get "undefined"
Can anyone help me how I can solve this issue?