|
22 | 22 | from bson.objectid import ObjectId |
23 | 23 | from bson.py3compat import iteritems, string_type, _unicode |
24 | 24 | from bson.son import SON |
25 | | -from pymongo import auth, common |
| 25 | +from pymongo import auth, common, helpers |
26 | 26 | from pymongo.collection import Collection |
27 | 27 | from pymongo.command_cursor import CommandCursor |
28 | 28 | from pymongo.errors import (CollectionInvalid, |
@@ -592,12 +592,16 @@ def current_op(self, include_all=False): |
592 | 592 | - `include_all` (optional): if ``True`` also list currently |
593 | 593 | idle operations in the result |
594 | 594 | """ |
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] |
601 | 605 |
|
602 | 606 | def profiling_level(self): |
603 | 607 | """Get the database's current profiling level. |
|
0 commit comments