Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Why does this Express API require a username

I had this API working for ages, but suddenly it has decided to die on me! I do not know why. I've tried to redact username, as I don't think it's required for my process.

I do not have username referenced or even apart of my schema at all. See below:

const UserSchema = new mongoose.Schema(
    {
        fullname:{type:String, required: true, default: "none"},
        email:{type:String, required: true, unique: true},
        position:{type:String, required: true, default: "none"},

        password:{type:String, required: true},
        company: {type:String, default: "none"},
        recruiter: {type: Boolean}, //Canidate or Recruiter

        isAdmin:{
            type: Boolean,
            default: false,
        },
    },
    {timestamps: true }
);


module.exports = mongoose.model("User", UserSchema)

With this, I am using the following route.

router.post("/register", async (req, res) => {
    const newUser = new User({
      fullname: req.body.fullname,
      email: req.body.email,
      position: req.body.position,
      // username: req.body.fullname,
      password: CryptoJS.AES.encrypt(
        req.body.password,
        process.env.PASS_SEC
      ).toString(),
    });
  
    try {
      const savedUser = await newUser.save();
      res.status(201).json(savedUser);
    } catch (err) {
      res.status(500).json(err);
    }
  });

If I then try to attempt to post this without the username there, despite it never being referenced I get this.

E.g, trial input:

{
    "fullname": "D D",
    "email": "trialforstack@hotmail.com",
    "position": "Data Analyst",
    "password": "nanana"
}

I then recieve this back from my post req. What the bloody hell am I doing wrong!

{
    "index": 0,
    "code": 11000,
    "keyPattern": {
        "username": 1
    },
    "keyValue": {
        "username": null
    }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!