I have a Users
collection and an Events
collection. The users collection is unremarkable, here's my events Schema:
schema = new mongoose.Schema({
user: {
type : mongoose.Schema.ObjectId,
ref : 'User',
required : true
},
name: {
type : String,
unique : true,
required : true
}
});
This works. I cannot create an event without a username and the name
property is required and unique. Problem is, it's unique on the database. So if user A creates an event called "Meet up", no other user can create an event with that name. I want the "uniqueness" to be restricted by user, so User A cannot create two events named "Meet up", but user B can create one with that name.
How would I approach this?