Automattic/mongoose · error · MongooseError
Cannot overwrite options in pre("save") hook on bulkSave()
Error message
Cannot overwrite options in pre("save") hook on bulkSave() What it means
Error "Cannot overwrite options in pre("save") hook on bulkSave()" thrown in Automattic/mongoose.
Source
Thrown at lib/model.js:3682
if (documentError == null) {
successfulDocuments.push(document);
}
}
await Promise.all(successfulDocuments.map(document => handleSuccessfulWrite(document, options)));
if (bulkWriteError != null) {
throw bulkWriteError;
}
return bulkWriteResult;
};
async function buildPreSavePromise(document, options) {
const preFilter = buildMiddlewareFilter(options, 'pre');
const [newOptions] = await document.schema.s.hooks.execPre('save', document, [options], { filter: preFilter });
if (newOptions !== options) {
throw new MongooseError('Cannot overwrite options in pre("save") hook on bulkSave()');
}
}
async function handleSuccessfulWrite(document, options) {
const wasNew = document.$isNew;
if (wasNew) {
_setIsNew(document, false);
}
document.$__reset();
// version key gets initialized to 0 when inserting a new document so avoid incrementing version key here
if (!wasNew) {
document._applyVersionIncrement();
}
const postFilter = buildMiddlewareFilter(options, 'post');
return document.schema.s.hooks.execPost('save', document, [document], { filter: postFilter });
}
View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/model.js:3682 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21).
Data as JSON: /api/errors/55e73193b99c4ff3.
Report an issue: GitHub.