@@ -309,19 +309,15 @@ def register_nodes():
309
309
310
310
311
311
class MongoQuerySet (QuerySet ):
312
- def raw_mql (self , raw_query , translations = None , using = None ):
313
- return MongoRawQuerySet (
314
- raw_query ,
315
- model = self .model ,
316
- translations = translations ,
317
- using = using ,
318
- )
312
+ def raw_mql (self , pipeline , using = None ):
313
+ return MongoRawQuerySet (pipeline , model = self .model , using = using )
319
314
320
315
321
316
class MongoRawQuery (RawQuery ):
322
- def __init__ (self , sql , using , model ):
323
- super ().__init__ (sql , using )
317
+ def __init__ (self , pipeline , using , model ):
318
+ super ().__init__ (sql = None , using = using )
324
319
self .model = model
320
+ self .pipeline = pipeline
325
321
326
322
def __iter__ (self ):
327
323
self ._execute_query ()
@@ -330,34 +326,34 @@ def __iter__(self):
330
326
def _execute_query (self ):
331
327
connection = connections [self .using ]
332
328
collection = connection .get_collection (self .model ._meta .db_table )
333
- self .cursor = collection .aggregate (self .sql )
329
+ self .cursor = collection .aggregate (self .pipeline )
334
330
335
331
def get_columns (self ):
336
332
return [f .column for f in self .model ._meta .fields ]
337
333
338
334
def __str__ (self ):
339
- return "%s" % self .sql
335
+ return "%s" % self .pipeline
340
336
341
337
342
338
class MongoRawQuerySet (RawQuerySet ):
343
339
def __init__ (
344
340
self ,
345
- raw_query ,
341
+ pipeline ,
346
342
model = None ,
347
343
query = None ,
348
344
translations = None ,
349
345
using = None ,
350
346
hints = None ,
351
347
):
352
348
super ().__init__ (
353
- raw_query ,
349
+ pipeline ,
354
350
model = model ,
355
351
query = query ,
356
352
using = using ,
357
353
hints = hints ,
358
354
translations = translations ,
359
355
)
360
- self .query = query or MongoRawQuery (sql = raw_query , using = self .db , model = self .model )
356
+ self .query = query or MongoRawQuery (pipeline , using = self .db , model = self .model )
361
357
362
358
def iterator (self ):
363
359
yield from MongoRawModelIterable (self )
0 commit comments