Mongoose: Why is create() not working and save() is?

Hi everyone

So, regarding the Exercuse Tracker exercise, I have code that works when I use save(). However, it does not work when I use create().

I realize that these two are parallel methods for achieving the same thing, and that create() is really a shortcut for creating a document and saving it to the database. I realize that they are used somewhat differently in terms of arguments, but I just don’t see what I’m doing wrong here.

This is working:

  // const user = new UserModel({
  //   username: req.body.username
  // });

  // user.save((err, doc) => {
  //   if (err || !doc) {
  //     console.error(err);
  //     return res.status(500).send("Database Error");
  //   }
  //   // console.log(doc);
  //   return res.status(201).json(doc);
  // });

But this isn’t:

const user = {
    username: req.body.username
  };

  try {
    const newUser = await UserModel.create(user);
  } catch (err) {
    res.status(500).json({ msg: "User cannot be created." });
  };

This is the schema:

const UserSchema = new Schema({
    username: String
});

What is missing from the create method?
Thank you!

Hello!

What part is not working? Is the document created on the database using create?

Can you provide a link to your project?