@@ -103,7 +103,7 @@ def order_by(self, compiler, connection):
103103 return self .expression .as_mql (compiler , connection )
104104
105105
106- def query (self , compiler , connection , get_wrapping_pipeline = None ):
106+ def query (self , compiler , connection , get_wrapping_pipeline = None , as_path = False ):
107107 subquery_compiler = self .get_compiler (connection = connection )
108108 subquery_compiler .pre_sql_setup (with_col_aliases = False )
109109 field_name , expr = subquery_compiler .columns [0 ]
@@ -145,6 +145,8 @@ def query(self, compiler, connection, get_wrapping_pipeline=None):
145145 # Erase project_fields since the required value is projected above.
146146 subquery .project_fields = None
147147 compiler .subqueries .append (subquery )
148+ if as_path :
149+ return f"{ table_output } .{ field_name } "
148150 return f"${ table_output } .{ field_name } "
149151
150152
@@ -167,20 +169,31 @@ def ref(self, compiler, connection, as_path=False): # noqa: ARG001
167169 return f"{ prefix } { refs } "
168170
169171
170- def star (self , compiler , connection ): # noqa: ARG001
172+ def star (self , compiler , connection , ** extra ): # noqa: ARG001
171173 return {"$literal" : True }
172174
173175
174- def subquery (self , compiler , connection , get_wrapping_pipeline = None ):
175- return self .query .as_mql (compiler , connection , get_wrapping_pipeline = get_wrapping_pipeline )
176+ def subquery (self , compiler , connection , get_wrapping_pipeline = None , ** extra ):
177+ return self .query .as_mql (
178+ compiler , connection , get_wrapping_pipeline = get_wrapping_pipeline , ** extra
179+ )
176180
177181
178- def exists (self , compiler , connection , get_wrapping_pipeline = None ):
182+ def exists (self , compiler , connection , get_wrapping_pipeline = None , as_path = False , ** extra ):
179183 try :
180- lhs_mql = subquery (self , compiler , connection , get_wrapping_pipeline = get_wrapping_pipeline )
184+ lhs_mql = subquery (
185+ self ,
186+ compiler ,
187+ connection ,
188+ get_wrapping_pipeline = get_wrapping_pipeline ,
189+ as_path = as_path ,
190+ ** extra ,
191+ )
181192 except EmptyResultSet :
182193 return Value (False ).as_mql (compiler , connection )
183- return connection .mongo_operators ["isnull" ](lhs_mql , False )
194+ if as_path :
195+ return connection .mongo_operators_match ["isnull" ](lhs_mql , False )
196+ return connection .mongo_operators_expr ["isnull" ](lhs_mql , False )
184197
185198
186199def when (self , compiler , connection , ** extra ):
0 commit comments