@@ -979,6 +979,21 @@ def validate_collection(self, name_or_collection,
979
979
980
980
return result
981
981
982
+ def _current_op (self , include_all = False , session = None ):
983
+ """Helper for running $currentOp."""
984
+ cmd = SON ([("currentOp" , 1 ), ("$all" , include_all )])
985
+ with self .__client ._socket_for_writes (session ) as sock_info :
986
+ if sock_info .max_wire_version >= 4 :
987
+ return self .__client .admin ._command (
988
+ sock_info , cmd , codec_options = self .codec_options ,
989
+ session = session )
990
+ else :
991
+ spec = {"$all" : True } if include_all else {}
992
+ return _first_batch (sock_info , "admin" , "$cmd.sys.inprog" ,
993
+ spec , - 1 , True , self .codec_options ,
994
+ ReadPreference .PRIMARY , cmd ,
995
+ self .client ._event_listeners )
996
+
982
997
def current_op (self , include_all = False , session = None ):
983
998
"""**DEPRECATED**: Get information on operations currently running.
984
999
@@ -1015,21 +1030,10 @@ def current_op(self, include_all=False, session=None):
1015
1030
.. _$currentOp aggregation pipeline stage: https://docs.mongodb.com/manual/reference/operator/aggregation/currentOp/
1016
1031
.. _currentOp command: https://docs.mongodb.com/manual/reference/command/currentOp/
1017
1032
"""
1018
- warnings .warn ("current_op() is deprecated. See the documentation for"
1033
+ warnings .warn ("current_op() is deprecated. See the documentation for "
1019
1034
"more information" ,
1020
1035
DeprecationWarning , stacklevel = 2 )
1021
- cmd = SON ([("currentOp" , 1 ), ("$all" , include_all )])
1022
- with self .__client ._socket_for_writes (session ) as sock_info :
1023
- if sock_info .max_wire_version >= 4 :
1024
- return self .__client .admin ._command (
1025
- sock_info , cmd , codec_options = self .codec_options ,
1026
- session = session )
1027
- else :
1028
- spec = {"$all" : True } if include_all else {}
1029
- return _first_batch (sock_info , "admin" , "$cmd.sys.inprog" ,
1030
- spec , - 1 , True , self .codec_options ,
1031
- ReadPreference .PRIMARY , cmd ,
1032
- self .client ._event_listeners )
1036
+ return self ._current_op (include_all , session )
1033
1037
1034
1038
def profiling_level (self , session = None ):
1035
1039
"""Get the database's current profiling level.
0 commit comments