• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

219
Views
MongoServerError: E11000 duplicate key error collection: MERNSM.users index: followers_1 dup key: { followers: undefined }

MongoServerError: E11000 duplicate key error collection: MERNSM.users index: followers_1 dup key: { followers: undefined } im confused as i dont have unique in my schema im not sure what the problem could be as i am creating a user with unique inputs but getting this error Register File

 export const Register = async (req,res) => {
    const user = req.body
  
    try{
        if (typeof(user.password) === "undefined" || typeof(user.username) === "undefined" ){
            res.status(205).json("Missing Details")
        }
        console.log(user)
       
        userModel.create({username:user.username,password:user.password,email:user.email})
        res.status(205).json("User Created")
    }catch(err){
        console.log("there was an error")
        res.status(405).json({messages:err.message})
    }
}

User Schema:

import Mongoose from "mongoose"

const userSchema = Mongoose.Schema({
   username:{type:String,required:true,unique:true},
   password:{type:String,required:true,},
   email:{type:String,required:true,unique:true},
   profileimg:{type:String,default:"https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png"},
   Bio:{type:String ,default:""},
   following:{type:Array,default:[]},
   followers:{type:Array,default:[]}
})

const userModel = Mongoose.model("Users",userSchema)
export default userModel  aw a   a 
about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

i had some weird error where the database was not updated so i had to drop the collection and create a new one

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error