I am very new to Node js and Mongoose module. I am trying to create a schema where there are some required fields, and some others may be dynamic.
I used strictto false. My code is as follows:
var mongoose = require('mongoose')
var db = mongoose.connect('mongodb://localhost/ets',function(err)
{
if(err) throw err
})
var Schema = mongoose.Schema
var Tasks = new Schema({vmProfile:String}, { strict: false });
mongoose.model('Task',Tasks)
var Task = mongoose.model('Task')
var task = new Task()
task.vmProfile = "required value"
task.otherKey = "something"
task.save(function(err)
{
if(err) throw err;
})
when I run this, I get only vmProfile, and not otherKey, the DB looks like this:
{ "vmProfile" : "required value", "_id" : ObjectId("53364a5a5cd71a76122f0a8a"), "__v" : 0 }
where am i making a mistake.
source
share