node.js - Mongoose Schema - Requiring one to be unique but not both -
i want store email string , password 1 needs unique. can use same email address 2 different passwords (or 100) , have 100 accounts passwords must different should still able have same password else long email address not same.
i can't seem find example of sort of thing in of mongoose schema docs.
using adreas suggestion have:
var userschema = new schema({ email: { type: string, required: true, index: true }, password: { type: string, required: true, index: true } }); //either email or password must unique if other not userschema.index({ "email": 1, "password": 1 }, { unique: true }); module.exports = mongoose.model('user', userschema);
it's still letting me use same email same pass.
compound index should need.
user.index({ email: 1, hashedpassword: 1 }, { unique: true });
implementing might security risk though, have have same salt on both accounts. don't store plain-text pls.
Comments
Post a Comment