Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -5194,4 +5199,4 @@ function _getContexts(hook) {
* Module exports.
*/

module.exports = exports = Model;
module.exports = Model;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion types/document.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,4 @@ declare module 'mongoose' {
validateSync<T extends keyof DocType>(pathsToValidate?: T | T[], options?: AnyObject): Error.ValidationError | null;
validateSync(pathsToValidate?: pathsToValidate, options?: AnyObject): Error.ValidationError | null;
}
}
}
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,4 +931,4 @@ declare module 'mongoose' {
export function skipMiddlewareFunction(val: any): Kareem.SkipWrappedFunction;

export default mongoose;
}
}