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

Confusing error messages for deprecated #10155

Closed
FrancisVila opened this issue Apr 19, 2021 · 2 comments
Closed

Confusing error messages for deprecated #10155

FrancisVila opened this issue Apr 19, 2021 · 2 comments
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@FrancisVila
Copy link

FrancisVila commented Apr 19, 2021

I get the following deprecated error:

  (node:10816) DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndModify` option set to false are deprecated. See: https://mongoosejs.com/docs/deprecations.html#findandmodify

What I would expect:

  • for the error message to tell me which commands to use, rather than suggesting setting an option to false. I imagine the people who decided to deprecate a command had reasons to do so; I'm starting out using this technology and I'd like to know how I'm supposed to use it. Setting an option to false sounds like sweeping the issue under the carpet.
  • the linked page does not clearly state what is deprecated and what is supposed to be the replacement
@IslandRhythms IslandRhythms added the developer-experience This issue improves error messages, debugging, or reporting label Apr 19, 2021
@vkarpov15
Copy link
Collaborator

The way to work around this issue is to add:

// Make Mongoose use `findOneAndUpdate()`. Note that this option is `true`
// by default, you need to set it to false.
mongoose.set('useFindAndModify', false);

Admittedly this is a case of sweeping an issue under the carpet: Mongoose's findOneAndUpdate() method was originally written as a helper that uses findAndModify() under the hood, but then the MongoDB driver introduced its own findOneAndUpdate() function, so we're trying to transition to using their findOneAndUpdate() while minimizing the risk of breaking changes. Sorry for the inconvenience and thanks for your patience 👍

@vkarpov15 vkarpov15 added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary and removed developer-experience This issue improves error messages, debugging, or reporting labels Apr 23, 2021
@FrancisVila
Copy link
Author

FrancisVila commented Apr 26, 2021

I would add in a phrase in the doc, such as (after the DeprecationWarnings) :

If you are using this command for the first time in this version, you can either:

  • ignore this warning - it should disappear once the new syntax becomes the default
  • set 'useFindAndModify' to false, as suggested

@vkarpov15 vkarpov15 reopened this Apr 27, 2021
@vkarpov15 vkarpov15 added docs This issue is due to a mistake or omission in the mongoosejs.com documentation and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary labels Apr 27, 2021
@vkarpov15 vkarpov15 added this to the 5.12.8 milestone Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

No branches or pull requests

3 participants