本文整理匯總了Python中pymongo.helpers._first_batch方法的典型用法代碼示例。如果您正苦於以下問題:Python helpers._first_batch方法的具體用法?Python helpers._first_batch怎麽用?Python helpers._first_batch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymongo.helpers
的用法示例。
在下文中一共展示了helpers._first_batch方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _list_collections
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _first_batch [as 別名]
def _list_collections(self, sock_info, slave_okay, criteria=None):
"""Internal listCollections helper."""
criteria = criteria or {}
cmd = SON([("listCollections", 1), ("cursor", {})])
if criteria:
cmd["filter"] = criteria
if sock_info.max_wire_version > 2:
coll = self["$cmd"]
cursor = self._command(sock_info, cmd, slave_okay)["cursor"]
return CommandCursor(coll, cursor, sock_info.address)
else:
coll = self["system.namespaces"]
res = _first_batch(sock_info, coll.database.name, coll.name,
criteria, 0, slave_okay,
CodecOptions(), ReadPreference.PRIMARY, cmd,
self.client._event_listeners)
data = res["data"]
cursor = {
"id": res["cursor_id"],
"firstBatch": data,
"ns": coll.full_name,
}
# Need to tell the cursor how many docs were in the first batch.
return CommandCursor(coll, cursor, sock_info.address, len(data))
示例2: current_op
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _first_batch [as 別名]
def current_op(self, include_all=False):
"""Get information on operations currently running.
:Parameters:
- `include_all` (optional): if ``True`` also list currently
idle operations in the result
"""
cmd = SON([("currentOp", 1), ("$all", include_all)])
with self.__client._socket_for_writes() as sock_info:
if sock_info.max_wire_version >= 4:
return sock_info.command("admin", cmd)
else:
spec = {"$all": True} if include_all else {}
x = helpers._first_batch(sock_info, "admin", "$cmd.sys.inprog",
spec, -1, True, self.codec_options,
ReadPreference.PRIMARY, cmd, self.client._event_listeners)
return x.get('data', [None])[0]