-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scoping a unique index to a user / compound indexes #3
Comments
+1 |
+1 |
Hi, I'm not really sure if this should be the same issue or not, but it seems similar given that my question concerns how to make a scoped unique index. I'm not doing much with OK, so I have this in my schema for a "chat room" record; it lists which users belong to that room. A room's user list can only contain a specific user once. The problem I'm having is that with this configuration, a user cannot be in multiple rooms. 'users': Array,
'users.$': Object,
'users.$._id': {
type: String,
unique: true,
custom: ->
user_id = @value
unless Meteor.users.findOne(user_id)
return "user_doesnt_exist" # a key added to setDefaultMessages
false
} when my app starts it creates a 'lobby' room that all users are added to through the In this use-case it only makes sense to scope the uniqueness to that particular room record; I don't want it to look at the users in the other rooms. If this feature isn't possible, then the alternative would have to be to re-implement the uniqueness check inside the This alternative isn't too hard, but I'm curious if this is something that is supported in this package but I'm failing to use correctly. |
I have an issue whereby each of my lead documents stores an email address and a reference to a user ID e.g.:
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:
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.The text was updated successfully, but these errors were encountered: