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
tarantoj opened this issue
Oct 19, 2019
· 2 comments
Labels
docsThis issue is due to a mistake or omission in the mongoosejs.com documentationhelpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Do you want to request a feature or report a bug?
Bug report
What is the current behavior?
Applying a transform to a document using toObject() or toJSON() methods is applied to subdocuments, conflicting with online documentation.
Transforms are applied only to the document and are not applied to sub-documents.
If the current behavior is a bug, please provide the steps to reproduce.
Create a document with a subdocument, call toObject() or toJSON() with a transform function. Test script
What is the expected behavior?
Transform to only be applied to the root document
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js: v12.12.0
Mongoose: 5.7.1
MongoDB: N/A
The text was updated successfully, but these errors were encountered:
tarantoj
changed the title
Transform functions are applied to nested documents
[bug] Transform functions are applied to nested documents
Oct 22, 2019
I think this behavior is intentional and the docs are misleading. The docs refer to transforms defined in the schema, like schema.options.toObject.transform. But if you pass a transform when calling toObject(), it applies to all documents, because otherwise the transform wouldn't be terribly useful.
Is this behavior causing you an issue?
vkarpov15
added
docs
This issue is due to a mistake or omission in the mongoosejs.com documentation
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
and removed
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
labels
Oct 26, 2019
Yeah, caused some problems when trying to use an inline transform function to remove sensitive data on an endpoint depending on the requested item and logged in user.
If recursive application of the transform function is intended behaviour, I'd agree with you that the docs could require some clarification, especially as I'm not the only one to find this one out the hard way.
docsThis issue is due to a mistake or omission in the mongoosejs.com documentationhelpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Do you want to request a feature or report a bug?
Bug report
What is the current behavior?
Applying a transform to a document using
toObject()
ortoJSON()
methods is applied to subdocuments, conflicting with online documentation.If the current behavior is a bug, please provide the steps to reproduce.
Create a document with a subdocument, call
toObject()
ortoJSON()
with atransform
function.Test script
What is the expected behavior?
Transform to only be applied to the root document
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js: v12.12.0
Mongoose: 5.7.1
MongoDB: N/A
The text was updated successfully, but these errors were encountered: