@@ -18,7 +18,7 @@ def test_not_supported(self):
1818 )._get_condition_mql (Article , schema_editor = editor )
1919
2020 def test_negated_not_supported (self ):
21- msg = "MongoDB does not support negated field in indexes."
21+ msg = "MongoDB does not support the '~' operator in indexes."
2222 with self .assertRaisesMessage (NotSupportedError , msg ), connection .schema_editor () as editor :
2323 Index (
2424 name = "test" ,
@@ -27,15 +27,15 @@ def test_negated_not_supported(self):
2727 )._get_condition_mql (Article , schema_editor = editor )
2828
2929 def test_xor_not_supported (self ):
30- msg = "MongoDB does not support the 'Xor' lookup in indexes."
30+ msg = "MongoDB does not support the '^' operator lookup in indexes."
3131 with self .assertRaisesMessage (NotSupportedError , msg ), connection .schema_editor () as editor :
3232 Index (
3333 name = "test" ,
3434 fields = ["headline" ],
3535 condition = Q (pk = True ) ^ Q (pk = False ),
3636 )._get_condition_mql (Article , schema_editor = editor )
3737
38- @skipIfDBFeature ("is_mongodb_6_0 " )
38+ @skipIfDBFeature ("supports_in_index_operator " )
3939 def test_or_not_supported (self ):
4040 msg = "MongoDB does not support the 'Or' lookup in indexes."
4141 with self .assertRaisesMessage (NotSupportedError , msg ), connection .schema_editor () as editor :
@@ -45,7 +45,7 @@ def test_or_not_supported(self):
4545 condition = Q (pk = True ) | Q (pk = False ),
4646 )._get_condition_mql (Article , schema_editor = editor )
4747
48- @skipIfDBFeature ("is_mongodb_6_0 " )
48+ @skipIfDBFeature ("supports_in_index_operator " )
4949 def test_in_not_supported (self ):
5050 msg = "MongoDB does not support the 'in' lookup in indexes."
5151 with self .assertRaisesMessage (NotSupportedError , msg ), connection .schema_editor () as editor :
@@ -55,21 +55,21 @@ def test_in_not_supported(self):
5555 condition = Q (pk__in = [True ]),
5656 )._get_condition_mql (Article , schema_editor = editor )
5757
58- @skipUnlessDBFeature ("is_mongodb_6_0 " )
58+ @skipUnlessDBFeature ("supports_in_index_operator " )
5959 def test_composite_index (self ):
6060 with connection .schema_editor () as editor :
6161 index = Index (
6262 name = "composite_proposition" ,
6363 fields = ["headline" ],
64- condition = Q (number__gte = 3 ) & (Q (text__gt = "test1" ) | Q (text__in = ["A" , "B" ])),
64+ condition = Q (number__gte = 3 ) & (Q (body__gt = "test1" ) | Q (body__in = ["A" , "B" ])),
6565 )
6666 index ._get_condition_mql (Article , schema_editor = editor )
6767 self .assertEqual (
6868 index ._get_condition_mql (Article , schema_editor = editor ),
6969 {
7070 "$and" : [
7171 {"number" : {"$gte" : 3 }},
72- {"$or" : [{"text " : {"$gt" : "test1" }}, {"text " : {"$in" : ["A" , "B" ]}}]},
72+ {"$or" : [{"body " : {"$gt" : "test1" }}, {"body " : {"$in" : ["A" , "B" ]}}]},
7373 ]
7474 },
7575 )
@@ -85,18 +85,23 @@ def test_composite_index(self):
8585 editor .remove_index (index = index , model = Article )
8686
8787 def test_composite_op_index (self ):
88- for op in (
89- [operator .or_ , operator .and_ ] if connection .features .is_mongodb_6_0 else [operator .and_ ]
90- ):
88+ operators = (
89+ (
90+ (operator .or_ , "$or" ),
91+ (operator .and_ , "$and" ),
92+ )
93+ if connection .features .supports_in_index_operator
94+ else ((operator .and_ , "$and" ),)
95+ )
96+ for op , mongo_operator in operators :
9197 with self .subTest (operator = op ), connection .schema_editor () as editor :
9298 index = Index (
9399 name = "composite_proposition" ,
94100 fields = ["headline" ],
95- condition = op (Q (number__gte = 3 ), Q (text__gt = "test1" )),
101+ condition = op (Q (number__gte = 3 ), Q (body__gt = "test1" )),
96102 )
97103 index ._get_condition_mql (Article , schema_editor = editor )
98- mongo_operator = "$and" if op == operator .and_ else "$or"
99- target = {mongo_operator : [{"number" : {"$gte" : 3 }}, {"text" : {"$gt" : "test1" }}]}
104+ target = {mongo_operator : [{"number" : {"$gte" : 3 }}, {"body" : {"$gt" : "test1" }}]}
100105 self .assertEqual (
101106 target ,
102107 index ._get_condition_mql (Article , schema_editor = editor ),
0 commit comments