TheOdinProject / curriculum

The open curriculum for learning web development
https://www.theodinproject.com/
Other
10.01k stars 13.4k forks source link

Bug: Mongoose versions >= 7.0 no longer accept callbacks #25187

Closed DutsAndrew closed 1 year ago

DutsAndrew commented 1 year ago

[x] I have thoroughly read and understand The Odin Project Contributing Guide [x] The title of this issue follows the Bug: brief description of bug format, e.g. Bug: Lesson complete button does not update on click [x] I would like to be assigned this issue to work on it


1. Description of the Bug: In the NodeJS Course and lesson "Authentication Basics" the tutorial asks you to install Mongoose to access mongoDB data to practice authentication. Mongoose versions >= 7.0 no longer accept callbacks rendering the following image unable to run in the tutorial.

Screen Shot 2023-03-07 at 16 56 05

2. How To Reproduce:

  1. Head to this lesson.
  2. Follow all steps down until you reach the following header: "Function one : setting up the LocalStrategy"
  3. The issue is found at "Function one : setting up the LocalStrategy", however it was not noticed until reaching the "Log in form" section
  4. Run your code on a localhost server to see callstack errors
  5. You should see the following error: MongooseError: Model.findOne() no longer accepts a callback at Function.findOne

3. Expected Behavior:

  1. the User.findOne({ username: username }, (err, user) => {} should run without issues

4. Desktop/Device:

5. Additional Information:

  1. I have found the following solutions to work well form stack overflow. There is a good thread about it here.

The current options talked about involve the following work-arounds: 1) uninstalling mongoose and rolling it back to 6.10.0: npm uninstall mongoose npm install mongoose@6.10.0, and

2) running a then/catch clause such as: myModel.find({}).then((res) => { //if succeded do this block of code }).catch((err) => { //catch error });

3) They do talk about running a .exec() function with the callback, but I did not have luck with this.

4) I'd suggest either editing the tutorial for this lesson to either installing the precise mongoose package and going over why, or adding solution 2 from this list as the acceptable way to run the screenshot mentioned above.

5) I have not gone back to look at the previous lessons to see if this issue persists with them as well, but this might require a larger change across multiple lessons.

CouchofTomato commented 1 year ago

All yours @DutsAndrew if you want to submit a PR to fix it

DutsAndrew commented 1 year ago

Sure thing, I'll get right on it