Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to skip invalid fields with castObject() #12156

Closed
2 tasks done
vkarpov15 opened this issue Jul 26, 2022 · 0 comments 路 Fixed by #12332
Closed
2 tasks done

Add option to skip invalid fields with castObject() #12156

vkarpov15 opened this issue Jul 26, 2022 · 0 comments 路 Fixed by #12332
Assignees
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Milestone

Comments

@vkarpov15
Copy link
Collaborator

vkarpov15 commented Jul 26, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

馃殌 Feature Proposal

Based on @AbdelrahmanHafez 's comments from #12120 (comment) . It would be nice to have an option that ignores invalid fields with castObject(), rather than throwing a CastError.

const Test = mongoose.model('Test', Schema({ name: String, age: Number }));

const res = Test.castObject({ name: 'John Smith', age: 'not a number' }, { ignoreCastErrors: true });

res.name; // 'John Smith'
res.age; // undefined

Motivation

Would be helpful if you want to use castObject() and want to take just the valid fields.

Example

No response

@vkarpov15 vkarpov15 added new feature This change adds new functionality, like a new method or class enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature labels Jul 26, 2022
@vkarpov15 vkarpov15 added this to the 6.x Unprioritized milestone Jul 26, 2022
@vkarpov15 vkarpov15 reopened this Jul 26, 2022
@vkarpov15 vkarpov15 modified the milestones: 6.x Unprioritized, 6.6 Aug 24, 2022
@IslandRhythms IslandRhythms linked a pull request Aug 25, 2022 that will close this issue
AbdelrahmanHafez added a commit that referenced this issue Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants