diff --git a/lib/model.js b/lib/model.js index 3929413e76..d00ac2cd1e 100644 --- a/lib/model.js +++ b/lib/model.js @@ -357,7 +357,12 @@ Model.prototype.$__handleSave = function(options, callback) { } if (this.$isNew) { // send entire doc - const obj = this.toObject(saveToObjectOptions); + let obj; + // Always use toObject for serialization; control minimize via options + saveToObjectOptions = Object.assign({}, saveToObjectOptions, { + minimize: this.$__schema.options.minimize + }); + obj = this.toObject(saveToObjectOptions); if ((obj || {})._id === void 0) { // documents must have an _id else mongoose won't know // what to update later if more changes are made. the user @@ -5194,4 +5199,4 @@ function _getContexts(hook) { * Module exports. */ -module.exports = exports = Model; +module.exports = Model; \ No newline at end of file diff --git a/package.json b/package.json index 8261ba39fe..83cb09006f 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "bson": "^6.10.4", "kareem": "2.6.3", "mongodb": "~6.20.0", + "mongoose": "^8.19.3", "mpath": "0.9.0", "mquery": "5.0.0", "ms": "2.1.3", diff --git a/types/document.d.ts b/types/document.d.ts index 8e5f5824a4..849d92a973 100644 --- a/types/document.d.ts +++ b/types/document.d.ts @@ -302,4 +302,4 @@ declare module 'mongoose' { validateSync(pathsToValidate?: T | T[], options?: AnyObject): Error.ValidationError | null; validateSync(pathsToValidate?: pathsToValidate, options?: AnyObject): Error.ValidationError | null; } -} +} \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts index 8e8b5ad67f..bac5572dc7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -931,4 +931,4 @@ declare module 'mongoose' { export function skipMiddlewareFunction(val: any): Kareem.SkipWrappedFunction; export default mongoose; -} +} \ No newline at end of file