Skip to content

Commit 1764aaa

Browse files
aherlihybehackett
authored andcommitted
PYTHON-979 - Use currentOp command
1 parent 0862de6 commit 1764aaa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

pymongo/database.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from bson.objectid import ObjectId
2323
from bson.py3compat import iteritems, string_type, _unicode
2424
from bson.son import SON
25-
from pymongo import auth, common
25+
from pymongo import auth, common, helpers
2626
from pymongo.collection import Collection
2727
from pymongo.command_cursor import CommandCursor
2828
from pymongo.errors import (CollectionInvalid,
@@ -592,12 +592,16 @@ def current_op(self, include_all=False):
592592
- `include_all` (optional): if ``True`` also list currently
593593
idle operations in the result
594594
"""
595-
coll = self.get_collection(
596-
"$cmd.sys.inprog", read_preference=ReadPreference.PRIMARY)
597-
if include_all:
598-
return coll.find_one({"$all": True})
599-
else:
600-
return coll.find_one()
595+
with self.__client._socket_for_writes() as sock_info:
596+
if sock_info.max_wire_version >= 4:
597+
return sock_info.command(
598+
"admin", SON([("currentOp", 1), ("$all", include_all)]))
599+
else:
600+
spec = {"$all": True} if include_all else {}
601+
x = helpers._first_batch(sock_info, "admin.$cmd.sys.inprog",
602+
spec, -1, True, self.codec_options,
603+
ReadPreference.PRIMARY)
604+
return x.get('data', [None])[0]
601605

602606
def profiling_level(self):
603607
"""Get the database's current profiling level.

0 commit comments

Comments
 (0)