I have a User schema like this, when a user registers I want to set the default value as null but also to be able to set this value as unique. I tried the solution from this post
I literally copied the same solution however I am still getting this error
MongoError: E11000 duplicate key error index: ppp-ng-dev.users.$mobile_1 dup key: { : null }
My Schema
const userSchema = new Schema({
mobile: {
type: Number,
required: false,
index: {
unique: true,
partialFilterExpression: {mobile: {$exists: true }}
},
default: null,
},
})
Why am I receiving this error even when the syntax is correct? (aparently)