This is almost certainly covered elsewhere, but:
If I have a single schema with an embedded sub-document, like so:
var ChildSchema = new Schema ({
name : {
type: String,
trim: true
},
user :{
type: String,
trim: true
}
})
var ParentSchema = new Schema ({
name : {
type: String,
trim: true
},
child : [ChildSchema]
})
How would I save the name of the ParentSchema to ParentSchema.name and to ChildSchema.name in the same .save() action? The following does not work at all.
ChildSchema.pre('save', function(next){
this.name = ParentSchema.name;
next();
});