Make queryset aggregates obey read_preference
This commit is contained in:
parent
a8d6e59a7a
commit
0bc6507df3
@ -1182,6 +1182,10 @@ class BaseQuerySet(object):
|
|||||||
|
|
||||||
pipeline = initial_pipeline + list(pipeline)
|
pipeline = initial_pipeline + list(pipeline)
|
||||||
|
|
||||||
|
if IS_PYMONGO_3 and self._read_preference is not None:
|
||||||
|
return self._collection.with_options(read_preference=self._read_preference) \
|
||||||
|
.aggregate(pipeline, cursor={}, **kwargs)
|
||||||
|
|
||||||
return self._collection.aggregate(pipeline, cursor={}, **kwargs)
|
return self._collection.aggregate(pipeline, cursor={}, **kwargs)
|
||||||
|
|
||||||
# JS functionality
|
# JS functionality
|
||||||
|
@ -4353,6 +4353,26 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertEqual(bars._cursor._Cursor__read_preference,
|
self.assertEqual(bars._cursor._Cursor__read_preference,
|
||||||
ReadPreference.SECONDARY_PREFERRED)
|
ReadPreference.SECONDARY_PREFERRED)
|
||||||
|
|
||||||
|
@needs_mongodb_v26
|
||||||
|
def test_read_preference_aggregation_framework(self):
|
||||||
|
class Bar(Document):
|
||||||
|
txt = StringField()
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
'indexes': ['txt']
|
||||||
|
}
|
||||||
|
# Aggregates with read_preference
|
||||||
|
bars = Bar.objects \
|
||||||
|
.read_preference(ReadPreference.SECONDARY_PREFERRED) \
|
||||||
|
.aggregate()
|
||||||
|
if IS_PYMONGO_3:
|
||||||
|
self.assertEqual(bars._CommandCursor__collection.read_preference,
|
||||||
|
ReadPreference.SECONDARY_PREFERRED)
|
||||||
|
else:
|
||||||
|
self.assertNotEqual(bars._CommandCursor__collection.read_preference,
|
||||||
|
ReadPreference.SECONDARY_PREFERRED)
|
||||||
|
|
||||||
|
|
||||||
def test_json_simple(self):
|
def test_json_simple(self):
|
||||||
|
|
||||||
class Embedded(EmbeddedDocument):
|
class Embedded(EmbeddedDocument):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user