skip to Main Content

here is my shcema file.

  name:{type:String,unique:true,required:true},
  email:{type:String,unique:true,required:true},
  userName:{type:String,unique:true,required:true},
  password:{type:String,unique:true,required:true},
  status:{type:String,unique:true,default:true}
},{timestamps:true})

And i’m converting the password in to bcrypt

2

Answers


  1. You can add .clone() after your MongoDB query, this will remove the E11000 duplicate key error

    Login or Signup to reply.
  2. Just remove the unique property in status. If you declare unique to true all the fields must have the unique value. The value of status will be either true or false. So duplication will occur.

    Use this schema:

    name: {
      type: String,
      required: true
    },
    email: {
      type: String,
      unique: true,
      required: true
    },
    userName: {
      type: String,
      required: true
    },
    password: {
      type: String,
      required: true
    },
    status: {
      type:String,
      default:true
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search