Open mthanded opened 9 months ago
Thank you @mthanded for the very detailed error report. I'm surprised both indices are not created properly 🤔
Anyway, as you suggest, it makes more sense to directly have the collation index unique since it's the behavior we adopt on Python's side.
PR welcome to solve this :)
Describe the bug
BeanieBaseUserDocument defines 2 indexes on the email field , one being a unique index and the other being a collation. However only the collation index is applied to the email field in the database. This means that multiple users with the same emaill can end up in the database.
To Reproduce
To make reproducing this simpler i have lifted the BeanieBaseUserDocument model directly from this repo and put it into a minimal example.
Model from https://github.com/fastapi-users/fastapi-users-db-beanie/blob/eedd1039cd8d3aece0f49fa1a90d9649ca80d1ee/fastapi_users_db_beanie/__init__.py#L16
The behavior is not as expected:
Instead of mongo complaining about the same email it allows multiple emails to be the same:
There is no unique index on the email field in the mongodb index list:
Expected behavior
The database should prevent duplicate emails from being added via the indexes.
Additional context
Software versions