If the batch_size
is provided to the find
method in PyMongo the same should be happen as what was shown above:
from pymongo import MongoClient
client = MongoClient()
db = client['test']
coll = db['foo']
cursor = coll.find({})
count = 0
for it in cursor:
count += 1
print("\r", count, end="")
# 2021-07-13T09:41:57.969-0400 I COMMAND [conn9] command test.foo command: find { find: "foo", filter: {}, lsid: { id: UUID("b15cdbe6-9a20-4b92-a904-d775aa03ff45") }, $db: "test", $readPreference: { mode: "primaryPreferred" } } planSummary: COLLSCAN cursorid:7580655042457658670 keysExamined:0 docsExamined:101 numYields:0 nreturned:101 reslen:4936 locks:{ ReplicationStateTransition: { acquireCount: { w: 1 } }, Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } }, Mutex: { acquireCount: { r: 1 } } } storage:{} protocol:op_msg 0ms
# 2021-07-13T09:41:57.971-0400 I COMMAND [conn9] command test.foo command: getMore { getMore: 7580655042457658670, collection: "foo", lsid: { id: UUID("b15cdbe6-9a20-4b92-a904-d775aa03ff45") }, $db: "test" } originatingCommand: { find: "foo", filter: {}, lsid: { id: UUID("b15cdbe6-9a20-4b92-a904-d775aa03ff45") }, $db: "test", $readPreference: { mode: "primaryPreferred" } } planSummary: COLLSCAN cursorid:7580655042457658670 keysExamined:0 docsExamined:199 cursorExhausted:1 numYields:1 nreturned:199 reslen:9737 locks:{ ReplicationStateTransition: { acquireCount: { w: 2 } }, Global: { acquireCount: { r: 2 } }, Database: { acquireCount: { r: 2 } }, Collection: { acquireCount: { r: 2 } }, Mutex: { acquireCount: { r: 1 } } } storage:{} protocol:op_msg 0ms
cursor = coll.find({}, batch_size=50)
count = 0
for it in cursor:
count += 1
print("\r", count, end="")
# 2021-07-13T09:44:36.152-0400 I COMMAND [conn14] command test.foo command: find { find: "foo", filter: {}, batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test", $readPreference: { mode: "primaryPreferred" } } planSummary: COLLSCAN cursorid:1790856328923279599 keysExamined:0 docsExamined:50 numYields:0 nreturned:50 reslen:2487 locks:{ ReplicationStateTransition: { acquireCount: { w: 1 } }, Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } }, Mutex: { acquireCount: { r: 1 } } } storage:{} protocol:op_msg 0ms
# 2021-07-13T09:44:36.154-0400 I COMMAND [conn14] command test.foo command: getMore { getMore: 1790856328923279599, collection: "foo", batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test" } originatingCommand: { find: "foo", filter: {}, batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test", $readPreference: { mode: "primaryPreferred" } } planSummary: COLLSCAN cursorid:1790856328923279599 keysExamined:0 docsExamined:50 numYields:0 nreturned:50 reslen:2486 locks:{ ReplicationStateTransition: { acquireCount: { w: 1 } }, Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } }, Mutex: { acquireCount: { r: 1 } } } storage:{} protocol:op_msg 0ms
# 2021-07-13T09:44:36.156-0400 I COMMAND [conn14] command test.foo command: getMore { getMore: 1790856328923279599, collection: "foo", batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test" } originatingCommand: { find: "foo", filter: {}, batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test", $readPreference: { mode: "primaryPreferred" } } planSummary: COLLSCAN cursorid:1790856328923279599 keysExamined:0 docsExamined:50 numYields:0 nreturned:50 reslen:2486 locks:{ ReplicationStateTransition: { acquireCount: { w: 1 } }, Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } }, Mutex: { acquireCount: { r: 1 } } } storage:{} protocol:op_msg 0ms
# 2021-07-13T09:44:36.157-0400 I COMMAND [conn14] command test.foo command: getMore { getMore: 1790856328923279599, collection: "foo", batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test" } originatingCommand: { find: "foo", filter: {}, batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test", $readPreference: { mode: "primaryPreferred" } } planSummary: COLLSCAN cursorid:1790856328923279599 keysExamined:0 docsExamined:50 numYields:0 nreturned:50 reslen:2486 locks:{ ReplicationStateTransition: { acquireCount: { w: 1 } }, Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } }, Mutex: { acquireCount: { r: 1 } } } storage:{} protocol:op_msg 0ms
# 2021-07-13T09:44:36.159-0400 I COMMAND [conn14] command test.foo command: getMore { getMore: 1790856328923279599, collection: "foo", batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test" } originatingCommand: { find: "foo", filter: {}, batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test", $readPreference: { mode: "primaryPreferred" } } planSummary: COLLSCAN cursorid:1790856328923279599 keysExamined:0 docsExamined:50 numYields:0 nreturned:50 reslen:2486 locks:{ ReplicationStateTransition: { acquireCount: { w: 1 } }, Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } }, Mutex: { acquireCount: { r: 1 } } } storage:{} protocol:op_msg 0ms
# 2021-07-13T09:44:36.160-0400 I COMMAND [conn14] command test.foo command: getMore { getMore: 1790856328923279599, collection: "foo", batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test" } originatingCommand: { find: "foo", filter: {}, batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test", $readPreference: { mode: "primaryPreferred" } } planSummary: COLLSCAN cursorid:1790856328923279599 keysExamined:0 docsExamined:50 numYields:0 nreturned:50 reslen:2486 locks:{ ReplicationStateTransition: { acquireCount: { w: 1 } }, Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } }, Mutex: { acquireCount: { r: 1 } } } storage:{} protocol:op_msg 0ms
# 2021-07-13T09:44:36.161-0400 I COMMAND [conn14] command test.foo command: getMore { getMore: 1790856328923279599, collection: "foo", batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test" } originatingCommand: { find: "foo", filter: {}, batchSize: 50, lsid: { id: UUID("196e2520-77b2-4e89-bf40-362459794300") }, $db: "test", $readPreference: { mode: "primaryPreferred" } } planSummary: COLLSCAN cursorid:1790856328923279599 keysExamined:0 docsExamined:0 cursorExhausted:1 numYields:0 nreturned:0 reslen:96 locks:{ ReplicationStateTransition: { acquireCount: { w: 1 } }, Global: { acquireCount: { r: 1 } }, Database: { acquireCount: { r: 1 } }, Collection: { acquireCount: { r: 1 } }, Mutex: { acquireCount: { r: 1 } } } storage:{} protocol:op_msg 0ms