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

Unique index constraint does not work on indexes that are using array matching #851

Open
Wizzerinus opened this issue Jul 13, 2023 · 0 comments

Comments

@Wizzerinus
Copy link

Wizzerinus commented Jul 13, 2023

So, MongoDB allows using indexes on lists like this:

collection.create_index("mike.first", unique=1)
collection.insert_one({"mike": [{"first": "value"}]})
collection.insert_one({"mike": [{"first": "value"}]})

Link to documentation

This will not work in MongoDB because both items include a list item with mike.[index].first == value. However, this is valid in Mongomock and causes my tests to fail.

My usecase: I have a login system that allows a user to have multiple login methods and am using an index of type [("login_methods.identifier", 1), ("login_methods.login_type", 1)] to prevent multiple users from having the same login method (while login_methods is a list).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant