Code -11000 --"keyPattern": { "email": 1}, "keyValue": { "email": null }

I have 3 collections in my database-- Users, Posts, type.
User model–const userSchema = new Schema( {
username:{
type:String,
required:true,
unique:true,
},
email:{
type:String,
required:true

},
password:{
type:String,
required:true,
},
profilePic:{
type:String,
default:"",
}

},
{timestamps:true}
);

const User = mongoose.model(‘User’, userSchema);

Post Model–
const postSchema = new Schema( {

title:{

type:String,

required:true,

unique:true,

},

description:{

type:String,

required:true,

},

photo:{

type:String,

required:false,

},

username:{

  type:String,

  required:true,

},

categories:{

  type:Array,

  required:false

},

},

{timestamps:true});

const Post = mongoose.model(‘Post’, postSchema);

Create Post worked once from postman. Now it gives me the following error.

Postman request–
{
“username”:“Mouse”,
“title”:“Cruise along”,
“description”:“The Island”
}

Response----

“index”: 0,

"code": 11000,

"keyPattern": {

    "email": 1

},

"keyValue": {

    "email": null

}

}

I am not sure what I am doing wrong!?

Hi @Pranoti_Savadi ,

The 11000 code is a duplicate key error. This means that one of the uniquely defined keys were duplicated by a document insert attempt.

Perhaps the title you are trying to create already exists in the database.

Maybe also the email is defined required but you maybe insert a null… not very familiar with mongoose error types.

Thanks
Pavel