-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: django
-
None
Dear Team,
InĀ
In the following function `django_mongodb_backend.indexes.get_pymongo_index_model` we are adding the partial filter expression on type of the field if the index to be added is declared unique in the models file.
if unique: kwargs["unique"] = True # Indexing on $type matches the value of most SQL databases by # allowing multiple null values for the unique constraint. if field: column = column_prefix + field.column filter_expression[column].update({"$type": field.db_type(schema_editor.connection)}) else: for field_name, _ in self.fields_orders: field_ = model._meta.get_field(field_name) filter_expression[field_.column].update( {"$type": field_.db_type(schema_editor.connection)} )
This results in making the index partial on Atlas and simple queries like `Book.objects.get(name='Mongo DB')` does not use the created index. I verified this on Atlas showing index usages as 0 and through query plans too. Remove the index and creating it manually on Atlas solved the problem but then I will have to do it everytime new migration is added with unique index or unique constraint.
Am I doing something wrong while writing the queries or is it an expected issue?
- related to
-
SERVER-29445 Support additional queries with partial indexes when type is string
-
- Backlog
-