简体   繁体   English

PyMongo Cursor batch_size 一次返回一个文档

[英]PyMongo Cursor batch_size returning one document at a time

I am trying to query a mongoDB with batch sizes.我正在尝试查询具有批量大小的 mongoDB。 When I apply the batch_size argument in .find() method, It returns the same thing as using no batch size.当我在 .find() 方法中应用 batch_size 参数时,它返回的结果与不使用批处理大小相同。 The code below returns one document at a time instead of the expected batch size.下面的代码一次返回一个文档,而不是预期的批量大小。

#MongoDB Connection
...
cursor = collection.find({'Time':{'$gt':58006}}, {'V1':1, 'V2':1}, batch_size=9)
for i in cursor: 
    print(i)

https://www.mongodb.com/docs/manual/reference/method/cursor.batchSize/ details the use of batch size. https://www.mongodb.com/docs/manual/reference/method/cursor.batchSize/详细说明批量大小的使用。

Specifies the number of documents to return in each batch of the response from the MongoDB instance.指定要在来自 MongoDB 实例的每批响应中返回的文档数。 In most cases, modifying the batch size will not affect the user or the application, as mongosh and most drivers return results as if MongoDB returned a single batch.在大多数情况下,修改批处理大小不会影响用户或应用程序,因为 mongosh 和大多数驱动程序返回结果就像 MongoDB 返回单个批处理一样。

If you just want to get n documents, use limit() .如果您只想获取n文档,请使用limit() https://pymongo.readthedocs.io/en/stable/api/pymongo/cursor.html#pymongo.cursor.Cursor.limit https://pymongo.readthedocs.io/en/stable/api/pymongo/cursor.html#pymongo.cursor.Cursor.limit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM