@@ -1642,8 +1642,18 @@ def aggregate(self, pipeline, **kwargs):
16421642
16431643 cmd .update (kwargs )
16441644
1645- result = self ._command (sock_info , cmd , slave_ok ,
1646- read_concern = self .read_concern )
1645+ # Apply this Collection's read concern if $out is not in the
1646+ # pipeline.
1647+ if sock_info .max_wire_version >= 4 and 'readConcern' not in cmd :
1648+ for stage in cmd ['pipeline' ]:
1649+ if '$out' in stage :
1650+ result = self ._command (sock_info , cmd , slave_ok )
1651+ break
1652+ else :
1653+ result = self ._command (sock_info , cmd , slave_ok ,
1654+ read_concern = self .read_concern )
1655+ else :
1656+ result = self ._command (sock_info , cmd , slave_ok )
16471657
16481658 if "cursor" in result :
16491659 cursor = result ["cursor" ]
@@ -1826,8 +1836,14 @@ def map_reduce(self, map, reduce, out, full_response=False, **kwargs):
18261836 cmd .update (kwargs )
18271837
18281838 with self ._socket_for_primary_reads () as (sock_info , slave_ok ):
1829- response = self ._command (
1830- sock_info , cmd , slave_ok , ReadPreference .PRIMARY )
1839+ if (sock_info .max_wire_version >= 4 and 'readConcern' not in cmd and
1840+ 'inline' in cmd ['out' ]):
1841+ response = self ._command (
1842+ sock_info , cmd , slave_ok , ReadPreference .PRIMARY ,
1843+ read_concern = self .read_concern )
1844+ else :
1845+ response = self ._command (
1846+ sock_info , cmd , slave_ok , ReadPreference .PRIMARY )
18311847
18321848 if full_response or not response .get ('result' ):
18331849 return response
@@ -1869,6 +1885,11 @@ def inline_map_reduce(self, map, reduce, full_response=False, **kwargs):
18691885 ("out" , {"inline" : 1 })])
18701886 cmd .update (kwargs )
18711887 with self ._socket_for_reads () as (sock_info , slave_ok ):
1888+ if sock_info .max_wire_version >= 4 and 'readConcern' not in cmd :
1889+ res = self ._command (sock_info , cmd , slave_ok ,
1890+ read_concern = self .read_concern )
1891+ else :
1892+ res = self ._command (sock_info , cmd , slave_ok )
18721893 res = self ._command (sock_info , cmd , slave_ok )
18731894
18741895 if full_response :
0 commit comments