We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 14b79a3 commit 3c25544Copy full SHA for 3c25544
django_mongodb/schema.py
@@ -113,13 +113,21 @@ def _get_name(field_names):
113
def add_index(self, model, index, unique=False):
114
if index.contains_expressions:
115
return
116
+ kwargs = {}
117
+ if unique:
118
+ kwargs = {
119
+ "partialFilterExpression": {index.fields_orders[0][0]: {"$type": "string"}},
120
+ "unique": True,
121
+ }
122
+ else:
123
124
idx = IndexModel(
125
[
126
(model._meta.get_field(field_name).column, 1 if order == "" else -1)
127
for field_name, order in index.fields_orders
128
],
129
name=index.name,
- unique=unique,
130
+ **kwargs,
131
)
132
self.connection.database[model._meta.db_table].create_indexes([idx])
133
0 commit comments