@@ -979,6 +979,21 @@ def validate_collection(self, name_or_collection,
979979
980980 return result
981981
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+
982997 def current_op (self , include_all = False , session = None ):
983998 """**DEPRECATED**: Get information on operations currently running.
984999
@@ -1015,21 +1030,10 @@ def current_op(self, include_all=False, session=None):
10151030 .. _$currentOp aggregation pipeline stage: https://docs.mongodb.com/manual/reference/operator/aggregation/currentOp/
10161031 .. _currentOp command: https://docs.mongodb.com/manual/reference/command/currentOp/
10171032 """
1018- warnings .warn ("current_op() is deprecated. See the documentation for"
1033+ warnings .warn ("current_op() is deprecated. See the documentation for "
10191034 "more information" ,
10201035 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 )
10331037
10341038 def profiling_level (self , session = None ):
10351039 """Get the database's current profiling level.
0 commit comments