Skip to content

Commit ca0d966

Browse files
committed
Edits
1 parent 86be3d4 commit ca0d966

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

django_mongodb_backend/indexes.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,6 @@ def builtin_lookup_idx(self, compiler, connection):
4040
return {lhs_mql: {operator: value}}
4141

4242

43-
def where_node_idx(self, compiler, connection):
44-
if self.connector == AND:
45-
operator = "$and"
46-
elif self.connector == XOR:
47-
raise NotSupportedError("MongoDB does not support the '^' operator lookup in indexes.")
48-
else:
49-
operator = "$or"
50-
if self.negated:
51-
raise NotSupportedError("MongoDB does not support the '~' operator in indexes.")
52-
children_mql = []
53-
for child in self.children:
54-
mql = child.as_mql_idx(compiler, connection)
55-
children_mql.append(mql)
56-
if len(children_mql) == 1:
57-
mql = children_mql[0]
58-
elif len(children_mql) > 1:
59-
mql = {operator: children_mql}
60-
else:
61-
mql = {}
62-
return mql
63-
64-
6543
def get_pymongo_index_model(self, model, schema_editor, field=None, unique=False, column_prefix=""):
6644
"""Return a pymongo IndexModel for this Django Index."""
6745
if self.contains_expressions:
@@ -101,6 +79,28 @@ def get_pymongo_index_model(self, model, schema_editor, field=None, unique=False
10179
return IndexModel(index_orders, name=self.name, **kwargs)
10280

10381

82+
def where_node_idx(self, compiler, connection):
83+
if self.connector == AND:
84+
operator = "$and"
85+
elif self.connector == XOR:
86+
raise NotSupportedError("MongoDB does not support the '^' operator lookup in indexes.")
87+
else:
88+
operator = "$or"
89+
if self.negated:
90+
raise NotSupportedError("MongoDB does not support the '~' operator in indexes.")
91+
children_mql = []
92+
for child in self.children:
93+
mql = child.as_mql_idx(compiler, connection)
94+
children_mql.append(mql)
95+
if len(children_mql) == 1:
96+
mql = children_mql[0]
97+
elif len(children_mql) > 1:
98+
mql = {operator: children_mql}
99+
else:
100+
mql = {}
101+
return mql
102+
103+
104104
def register_indexes():
105105
BuiltinLookup.as_mql_idx = builtin_lookup_idx
106106
Index._get_condition_mql = _get_condition_mql

django_mongodb_backend/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def add_index(
261261
self, model, index, *, field=None, unique=False, column_prefix="", parent_model=None
262262
):
263263
idx = index.get_pymongo_index_model(
264-
model, self, field=field, unique=unique, column_prefix=column_prefix
264+
model, schema_editor=self, field=field, unique=unique, column_prefix=column_prefix
265265
)
266266
if idx:
267267
model = parent_model or model

0 commit comments

Comments
 (0)