Error while trying to connect with js code and mongodb

So I've been trying to figure this error and I couldn't find any solution everywhere. After sometime I know where the problem is but I don't know why:

    const savedUser = await newUser.save(); 

I believe that here is the problem because it keeps catching the consol.log("not working")

This is my code:

const router = require("express").Router();
const User = require("../models/User");

router.post("/register", async (req, res) => {
  const newUser = new User({
    username: req.body.username,
    email: req.body.email,
    password: req.body.password,
  });

  try {
    const savedUser = await newUser.save(); //I believe here is the problem
    res.status(201).json(savedUser);
  } catch (err) {
    console.log("not working");
    res.status(500).json(err);
  }
});
module.exports = router;

and I'm using postman I put the boy as raw and Json:

{
    "username":"lama",
    "email":"lama@gmail.com",
    "password":"12345"

}

and for some reason I get this as a result:

{
    "ok": 0,
    "code": 8000,
    "codeName": "AtlasError"
}

Thank you in advance!



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations