var childSchema = mongoose.Schema({
name: String,
age: Number,
toy: String
});
var adult = mongoose.Schema({
name: String,
age: Number,
married: Boolean,
child: {type: mongoose.Schema.Types.Mixed} // I use mixed so im able to put just 1 child of type childSchema in here,
//storing it in the initial employer schema
});
var employerSchema = mongoose.Schema({
name: String,
company: String,
employee: {type: mongoose.Schema.Types.Mixed} // I use mixed so ill be able to put in only 1 employee
});
employerModel.findOne({name: "employer_name"}, {lean: false}, function(err, employer){
// Check if the query worked out
if(err || employer == null) handleErr();
// We have an employer document now, change stuff for adult and child
employer.employee.name = "alteredname";
employer.employee.child.toy = "latestXBOX";
// Next step is to simply save this altered employer, and voilla, it should be solved, or so i thought
employer.save(function(error, saved_employer){
// Check if it worked
if(error || saved_employer == null) handleErr();
// It worked (at least in my case)
// All variables are nicely set as i wanted them, id think it is successfull... but ofcourse im not
console.log(JSON.stringify(saved_employer));
});
});