3030
3131# EXTRA IS TOTALLY IGNORED
3232# shall check if we could optimize match here
33- def case (self , compiler , connection , ** extra ): # noqa: ARG001
33+ def case (self , compiler , connection , as_path = False ):
3434 case_parts = []
3535 for case in self .cases :
3636 case_mql = {}
@@ -47,12 +47,16 @@ def case(self, compiler, connection, **extra): # noqa: ARG001
4747 default_mql = self .default .as_mql (compiler , connection )
4848 if not case_parts :
4949 return default_mql
50- return {
50+ expr = {
5151 "$switch" : {
5252 "branches" : case_parts ,
5353 "default" : default_mql ,
5454 }
5555 }
56+ if as_path :
57+ return {"$expr" : expr }
58+
59+ return expr
5660
5761
5862def col (self , compiler , connection , as_path = False ): # noqa: ARG001
@@ -98,6 +102,7 @@ def expression_wrapper(self, compiler, connection, **extra):
98102
99103
100104def negated_expression (self , compiler , connection , ** extra ):
105+ # review
101106 return {"$not" : expression_wrapper (self , compiler , connection , ** extra )}
102107
103108
@@ -175,10 +180,13 @@ def star(self, compiler, connection, **extra): # noqa: ARG001
175180 return {"$literal" : True }
176181
177182
178- def subquery (self , compiler , connection , get_wrapping_pipeline = None , ** extra ):
179- return self .query .as_mql (
180- compiler , connection , get_wrapping_pipeline = get_wrapping_pipeline , ** extra
183+ def subquery (self , compiler , connection , get_wrapping_pipeline = None , as_path = False ):
184+ expr = self .query .as_mql (
185+ compiler , connection , get_wrapping_pipeline = get_wrapping_pipeline , as_path = False
181186 )
187+ if as_path :
188+ return {"$expr" : expr }
189+ return expr
182190
183191
184192def exists (self , compiler , connection , get_wrapping_pipeline = None , as_path = False , ** extra ):
@@ -194,7 +202,7 @@ def exists(self, compiler, connection, get_wrapping_pipeline=None, as_path=False
194202 except EmptyResultSet :
195203 return Value (False ).as_mql (compiler , connection )
196204 if as_path :
197- return connection .mongo_operators_match ["isnull" ](lhs_mql , False )
205+ return { "$expr" : connection .mongo_operators_match ["isnull" ](lhs_mql , False )}
198206 return connection .mongo_operators_expr ["isnull" ](lhs_mql , False )
199207
200208
0 commit comments