-
-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Labels
Description
I have an issue whereby each of my lead documents stores an email address and a reference to a user ID e.g.:
{
userId: 1234,
email: '[email protected]'
}
I need different users to be able to create lead documents with the same email address. But they shouldn't be able to create a lead with a duplicate email.
If I use the following in my schema:
{
"email": {
type: String,
index: true,
unique: true
}
}
Then it doesn't respect the scoping of the index to the user so if a second user tries to create a lead with an email address already in use by a lead owned by another user, it fails validation.
I'm just wondering if it's possible to create a compound index as you would with the undocumented Collection._ensureIndex
e.g.
Leads._ensureIndex(
{ userId: 1, email: 1 },
{ unique: 1 }
);