@@ -103,7 +103,7 @@ def order_by(self, compiler, connection):
103
103
return self .expression .as_mql (compiler , connection )
104
104
105
105
106
- def query (self , compiler , connection , get_wrapping_pipeline = None ):
106
+ def query (self , compiler , connection , get_wrapping_pipeline = None , as_path = False ):
107
107
subquery_compiler = self .get_compiler (connection = connection )
108
108
subquery_compiler .pre_sql_setup (with_col_aliases = False )
109
109
field_name , expr = subquery_compiler .columns [0 ]
@@ -145,6 +145,8 @@ def query(self, compiler, connection, get_wrapping_pipeline=None):
145
145
# Erase project_fields since the required value is projected above.
146
146
subquery .project_fields = None
147
147
compiler .subqueries .append (subquery )
148
+ if as_path :
149
+ return f"{ table_output } .{ field_name } "
148
150
return f"${ table_output } .{ field_name } "
149
151
150
152
@@ -167,20 +169,31 @@ def ref(self, compiler, connection, as_path=False): # noqa: ARG001
167
169
return f"{ prefix } { refs } "
168
170
169
171
170
- def star (self , compiler , connection ): # noqa: ARG001
172
+ def star (self , compiler , connection , ** extra ): # noqa: ARG001
171
173
return {"$literal" : True }
172
174
173
175
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
+ )
176
180
177
181
178
- def exists (self , compiler , connection , get_wrapping_pipeline = None ):
182
+ def exists (self , compiler , connection , get_wrapping_pipeline = None , as_path = False , ** extra ):
179
183
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
+ )
181
192
except EmptyResultSet :
182
193
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 )
184
197
185
198
186
199
def when (self , compiler , connection , ** extra ):
0 commit comments