I am using a ‘post’ middleware hook in Mongoose to run some external promises and then possibly update the document with retrieved data values.
The issue is that updating the document triggers the ‘post’ middleware hook again.
Is there a property I can pass into the ‘findOneAndUpdate’ function to skip the middleware ?
Here is some example code:
<code>xxxSchema.post('findOneAndUpdate',async function (document) {
try {
if (true) {
await this.model.findOneAndUpdate({_id}, {"$set" : { "a" : 1}}) // <-- pass a property into here to not trigger the pre/post middleware again
console.log('done')
}
} catch (e) {
console.log(e);
}
})
</code>
<code>xxxSchema.post('findOneAndUpdate',async function (document) {
try {
if (true) {
await this.model.findOneAndUpdate({_id}, {"$set" : { "a" : 1}}) // <-- pass a property into here to not trigger the pre/post middleware again
console.log('done')
}
} catch (e) {
console.log(e);
}
})
</code>
xxxSchema.post('findOneAndUpdate',async function (document) {
try {
if (true) {
await this.model.findOneAndUpdate({_id}, {"$set" : { "a" : 1}}) // <-- pass a property into here to not trigger the pre/post middleware again
console.log('done')
}
} catch (e) {
console.log(e);
}
})