You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constmongoose=require('mongoose');constassert=require('assert');constschema=newmongoose.Schema({name: String,docArr: [{name: String}]});constTestModel=mongoose.model('Test',schema);constdoc=newTestModel({name: 'test',docArr: [{name: 'test'}]});// pass the transform as an inline option. Deletes `_id` property// from both the top-level document and the subdocument.constobj=doc.toObject({transform: deleteId});assert.equal(obj._id,undefined);assert.equal(obj.docArr[0]._id,undefined);functiondeleteId(doc,ret,options){deleteret._id;returnret;}
Prerequisites
Mongoose version
8.3.4
Node.js version
20.12.2
MongoDB server version
7.0.2
Typescript version (if applicable)
5.4.5
Description
When calling
myDocument.toObject
with options, for example to remove the _id, the options do not seem to apply to subdocuments.The documentation specifies (https://mongoosejs.com/docs/api/document.html#Document.prototype.toObject())
It worked with 8.3.3 and seems broken in 8.3.4
Steps to Reproduce
The test fails in 8.3.4 with
Expected Behavior
Any transform function specified in
toObject
options also propagates to any subdocuments.Thanks
The text was updated successfully, but these errors were encountered: