Create and Save a Record of a Model missing'done()' argument

What’s wrong with my code? It’s like the hint and all the solutions I’ve found are from 2021 where there was an extra function call that they had to comment out/delete but that isn’t here. I also checked the mongodb i created and in my collections i cant see anything new created.

const createAndSavePerson = (done) => {
  const johnDoe = new Person({
    name: "John Doe",
    age: 30,
    favoriteFoods: ["Pizza", "Pasta", "Salad"]
  });

  johnDoe.save((err, data) => {
    if (err) return done(err);
    done(null, data);
  });
};
  • try using a console log for “data” in this block see if this gets run or not
  • does this give any error?
  • also share this “step/exercise” url
  • also “repl” link for more context would be useful
    happy coding :slight_smile:

im using gitpod but i think it’s a problem is with the mongoose version i’m on? when i print mongoose.version it give me the output of 8.4.4 so I had to change the connect code to mongoose.connect(uri) and when i try to submit the code to see the output i get this error mainly:

/workspace/boilerplate-mongomongoose/node_modules/mongoose/lib/model.js:553 throw new MongooseError('Model.prototype.save() no longer accepts a callback');

my package.json is unchanged and is at ^5.11.15 and I can’t figure out how to downgrade mongoose to a version before 7.x

EDIT: managed to downgrade to 5.11.15 but when running “npm start” i get this error:

DeprecationWarning: The URL mongodb://<username>:<password>@ac-xk31pkq-shard-00-00.n0g8a3n.mongodb.net:27017,ac-xk31pkq-shard-00-01.n0g8a3n.mongodb.net:27017,ac-xk31pkq-shard-00-02.n0g8a3n.mongodb.net:27017/db1?authSource=admin&replicaSet=atlas-10wej6-shard-0&retryWrites=true&w=majority&appName=fcc-course&ssl=true is invalid. Future versions of Node.js will throw an error.

searching for the error online leads me to upgrading mongoose again and that’s just a loop to my initial probelm.

lowkey no idea what i did, i just unintalled mongoose and installed it again to get 5.11.15 and submitted it again and it worked

1 Like

Should console log for “data” be output in the terminal? I’m completing this challenge locally after cloning the repo, but I don’t see any log being output to the terminal or browser.

Also I’m passing the challenge but my mongodb cluster is not populating with any data.

I would assume you should be able to log it out. What is your code?

As for the DB, as far as I can tell the test calls remove on it after it is done (line 104 in server.js). So I’m guessing it is deleted so you won’t see it in the DB. You can probably check the DB logs to see if the write/delete is happening (I would assume it is).


If you need more help, you should open your own thread and post your code.

Thanks for the reply, I was able to get the message to log out into my terminal by upgrading my version of mongoose to latest (8.8.4) and refactoring my code to remove the callback to model.save(). The records are also now being added to the DB, however I’m running into issues with server.js for the other challenges. I’ll start a new thread for these issues.