Skip to content
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

Works without aliases shouldn't be included in user,alias index #41

Open
petli opened this issue Jul 11, 2014 · 1 comment
Open

Works without aliases shouldn't be included in user,alias index #41

petli opened this issue Jul 11, 2014 · 1 comment
Labels

Comments

@petli
Copy link
Member

petli commented Jul 11, 2014

The intention in the data model is that Work.alias should be optional. However, when creating works without an alias it is still included in this index, despite the sparse flag.

Work.index({ 'owner.user': 1, 'alias': 1 }, { unique: true, sparse: true });

Which results in a duplicate key error when the same users creates another work without an alias.

@ebalder
Copy link
Contributor

ebalder commented Jul 14, 2014

It's a problem with the compound sparse key implementation from MongoDB. If any of both keys is present, both are going to be included in the index.

Directly in the mongo shell:
- adding a work with no owner nor alias: no problem
- adding a work with duplicate owner and no alias: dup-key error
- adding a work with duplicate alias and no owner: dup-key error

related: https://jira.mongodb.org/browse/SERVER-2193

I would then proppose to add the work id in place of the alias if it's not set. But that would increase the size of the index.

@petli petli added the bug label Aug 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants