Mongodb – How to make Mongoose unique key validation to pass if other key is different?
Lets say we have this model : const userSchema = new mongoose.Schema({ username: { type: String, unique: true, uniqueCaseInsensitive: true, required: true, }, organisation: { type: Schema.Types.ObjectId, ref: "organisation", } }); const UserModel: mongoose.model("user", userSchema), and we already have this…