Seeking help with utilizing data from a recently created document to update a value using a 'pre' hook.
An example of the model being used:
...
title: {
type: String,
required: true
},
company: {
type: mongoose.Schema.ObjectId,
ref: 'Company',
required: true
}
...
The 'pre' hook in question:
jobSchema.pre('save', function(next) {
const jobTitle = slugify(this.title, { lower: true })
const companyName = slugify(this.company.name, { lower: true })
this.slug = jobTitle + companyName
next()
})
Encountering difficulty accessing this.company
within the hook and exploring potential solutions.