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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using patch to update field with alias is not working properly #387

Open
florianbepunkt opened this issue Aug 18, 2018 · 0 comments
Open

Comments

@florianbepunkt
Copy link

Not really sure if this is a bug or by design... if you declare an alias for a field. And then try to update the field (not the alias) via PATCH, the update does not go through and no error message or warning is thrown.

For example consider this schema

const GameSchema = new mongoose.Schema(
  {
    startDate: {
      type: Date,
      alias: 'startRound1',
    },
  },
  {
    minimize: false,
    toObject: {
      virtuals: true,
    },
    toJSON: {
      virtuals: true,
    },
    timestamps: true,
  }
);

If you want to update startDate field via PATCH method it returns a 200 status code but the update is no applied. Furthermore if you read the request with preUpdate method, the correct updated value is received within the request body, but if you read the result in postUpdate method, the old value is applied.

My guesss is, this is due to a missmatch in value between the "real" field (startDate) and its alias "startRound1". As far as I know this does not reflectthe way mongoose handles this. I think the original field should always precede its own alias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant