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

Allow to update doc with a discriminatorKey in $set #13055

Closed
2 tasks done
abarriel opened this issue Feb 20, 2023 · 0 comments
Closed
2 tasks done

Allow to update doc with a discriminatorKey in $set #13055

abarriel opened this issue Feb 20, 2023 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@abarriel
Copy link
Contributor

abarriel commented Feb 20, 2023

Prerequisites

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

馃殌 Feature Proposal

Hello, I would like to knows, if we can allow updating a doc with a data containing the discriminatorKey, but the value of the discriminatorKey is the same, thus no override

Motivation

This allows user to perform a full update, without having to taking care of removing discriminatorKey from is updatedData

Example

diff --git a/lib/helpers/query/castUpdate.js b/lib/helpers/query/castUpdate.js
index 2e1dde1a6c0827f65e2be252cf317e329c927566..cd9f58f6aca18e3eb44ede56794e478bd3de43d8 100644
--- a/lib/helpers/query/castUpdate.js
+++ b/lib/helpers/query/castUpdate.js
@@ -207,7 +207,7 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {
     if (
       schema.discriminatorMapping != null &&
       discriminatorKey === schema.options.discriminatorKey &&
-      !options.overwriteDiscriminatorKey
+      !options.overwriteDiscriminatorKey && schema.discriminatorMapping.value !== obj[key]
     ) {
       if (strictMode === 'throw') {
         const err = new Error('Can\'t modify discriminator key "' + discriminatorKey + '" on discriminator model');
@abarriel abarriel added 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 labels Feb 20, 2023
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed 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 Feb 21, 2023
@vkarpov15 vkarpov15 added this to the 6.9.3 milestone Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants