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

return value from super.delete() #12777

Merged
merged 1 commit into from
Dec 16, 2022

Conversation

danbrud
Copy link

@danbrud danbrud commented Dec 7, 2022

Summary

Currently, the Mongoose Map type doesn't abide by the native JS map API. The map's delete method should return true if the item was deleted and false if not as described here.

In order to abide by the native API and be more predictable to use I have simply returned the value that is returned by the super.delete method

Examples

const accountSchema = new mongoose.Schema({
  id: Number,
  shops: { type: Map, of: String }
})

const Account = mongoose.model('Account', accountSchema);

const newAccount = new Account({ id: 1, shops: { one: '111', two: '222' } });
await newAccount.save();

const wasDeletedWhenKeyExists = mapInstance.delete('one');
// Before change: wasDeletedWhenKeyExists == undefined
// After change: wasDeletedWhenKeyExists == true

const wasDeletedWhenKeyNotExists = mapInstance.delete('one');
// Before change: wasDeletedWhenKeyNotExists == undefined
// After change: wasDeletedWhenKeyNotExists == false

@vkarpov15 vkarpov15 added this to the 6.8.1 milestone Dec 16, 2022
Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@vkarpov15 vkarpov15 merged commit e8a3309 into Automattic:master Dec 16, 2022
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

Successfully merging this pull request may close these issues.

3 participants