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

TypeError: Pet.findByIdAndRemove is not a function #2

Open
wandrey7 opened this issue Apr 30, 2024 · 0 comments
Open

TypeError: Pet.findByIdAndRemove is not a function #2

wandrey7 opened this issue Apr 30, 2024 · 0 comments

Comments

@wandrey7
Copy link

Pra galera que instalou a nova versão e deu erro, a solução é essa:

Depois que o Mongoose saiu da versão 6.12.8 o findByIdAndRemove foi descontinuado, segundo a documentação deles a substituição é feita por findOneAndDelete.

Antes: await Pet.findByIdAndRemove({ _id: id });
Depois: await Pet.findOneAndDelete({ _id: id });

O erro está na Seção 15 - Projeto3 Get A Pet (API, RESTful, Express, MVC, MongoDB com Mongoose, React)
https://github.com/matheusbattisti/curso_node/blob/main/15_GETAPET/backend/controllers/PetController.js

{
    "message": "Erro ao remover o pet",
    "error": {}
}

TypeError: Pet.findByIdAndRemove is not a function
    at removePetById (F:\teste js\nodejs\15_get_a_pet\backend\controllers\PetController.js:146:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
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