mdn / express-locallibrary-tutorial

Local Library website written in NodeJS/Express; example for the MDN server-side development NodeJS module: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs.
Creative Commons Zero v1.0 Universal
1.23k stars 695 forks source link

error in populating database step: mongoose now installs 7.0 which doesn't use callbacks #165

Closed danbraun closed 1 year ago

danbraun commented 1 year ago

Before submitting the issue, check you have done the following:

What was incorrect, unhelpful, or unexpected?

During the step where we add dummy data with populatedb.js it fails and reports an error: MongooseError: Model.prototype.save() no longer accepts a callback

What did you expect to see?

Books, authors etc are added to the database

Output logs

node populatedb 'mongodb+srv://:@cluster0.23ogx.mongodb.net/local_library?retryWrites=true&w=majority' This script populates some test books, authors, genres and bookinstances to your database. Specified database as argument - e.g.: node populatedb "mongodb+srv://cooluser:coolpassword@cluster0.lz91hw2.mongodb.net/local_library?retryWrites=true&w=majority" /Users/daniel/Developer/express-locallibrary-tutorial/node_modules/mongoose/lib/model.js:497 throw new MongooseError('Model.prototype.save() no longer accepts a callback'); ^

MongooseError: Model.prototype.save() no longer accepts a callback at model.save (/Users/daniel/Developer/express-locallibrary-tutorial/node_modules/mongoose/lib/model.js:497:11) at authorCreate (/Users/daniel/Developer/express-locallibrary-tutorial/populatedb.js:37:10) at /Users/daniel/Developer/express-locallibrary-tutorial/populatedb.js:109:11 at /Users/daniel/Developer/express-locallibrary-tutorial/node_modules/async/dist/async.js:3674:28 at replenish (/Users/daniel/Developer/express-locallibrary-tutorial/node_modules/async/dist/async.js:446:21) at /Users/daniel/Developer/express-locallibrary-tutorial/node_modules/async/dist/async.js:451:13 at eachOfLimit$1 (/Users/daniel/Developer/express-locallibrary-tutorial/node_modules/async/dist/async.js:477:34) at awaitable (/Users/daniel/Developer/express-locallibrary-tutorial/node_modules/async/dist/async.js:211:32) at eachOfSeries (/Users/daniel/Developer/express-locallibrary-tutorial/node_modules/async/dist/async.js:813:16) at awaitable (/Users/daniel/Developer/express-locallibrary-tutorial/node_modules/async/dist/async.js:211:32)

Do you have anything more you want to share?

Downgrading mongoose to 6.9.0 solved the issue

github-actions[bot] commented 1 year ago

It looks like this is your first issue. Welcome! 👋 One of the project maintainers will be with you as soon as possible. We appreciate your patience. To safeguard the health of the project, please take a moment to read our code of conduct.

hamishwillee commented 1 year ago

Thanks. Closing as a duplicate.

I patched the docs this morning to use 6.9.0. That should go live in a day or two. I'll do a proper update at some point but it is a more serious job.