I have the two mongoose schemas where one schema reference the other. For example I have
const loginsSchema = new mongoose.Schema({
displayName:{
type:String,
required:true,
},
serviceId:{
required:true,
type:String,
unique:true
}
})
const logins = mongoose.model('logins',loginsSchema);
module.exports = logins;
const usersSchema = new mongoose.Schema({
userName: {
type: String,
required: true,
},
email: {
type: String,
unique: true,
},
user: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'logins',
unique: true
}
})
What I would like to do is to create a new schema and reference the userSchema in it but not with the objectid. I would like to use the email property.
For Example
const usersSchema = new mongoose.Schema({
name1: {
type: String,
required: true,
},
name2: {
type: String,
unique: true,
},
emailref: {
/// reference the username schema with the email property instead of the objectId
}
})
How can I do that in mongoose?