MongoDB,批量查找什么return

MongoDB, what does bulk find return

我正在尝试使用批量查找来检索一组文档和 return 集合,我想知道批量查找 return 是什么?我的代码是:

 def bulk_find(collection_name, key, value):

    bulk = db[collection_name].initialize_ordered_bulk_op()

    bulk.find({key: value})

    results = bulk.execute()

那么,bulk.find return 是什么意思?该文档没有具体说明。

它是 returns BulkWriteOperation 实例。来自 documentation

find(selector)
Specify selection criteria for bulk operations.

Parameters: 
selector (dict): the selection criteria for update and remove operations.
Returns:    
A BulkWriteOperation instance, used to add update and remove operations to this bulk operation.

pymongobulk is a write operations interface. If you want to retrieve multiply documents from some collection you should use method find对应的集合中。你只需要

results = db[collection_name].find({key:value})

此操作 returns 来自集合 collection_name 的所有文档,其中 key 字段的值 == value.

bulk.find return 一个界面允许您将多个操作分组到 select 数据。

例如更新,删除。

将查询分组并分批发送给MongodB执行非常高效。例如您想要增加来自特定供应商的产品的销售佣金。这个委托不是直截了当的,你必须对其应用一些逻辑。

通常,如果没有 bulk.find...,您将检索所有匹配的文档,进行更改并发送回服务器以保存。

在 bulk.find 的情况下,您实际上是在做同样的事情,但不是将每个文档单独发送回服务器,而是继续批量缓存它们。调用 bulk.execute 后,驱动程序会将所有更改捆绑在一起 并将它们发送到服务器。

详情请见https://docs.mongodb.org/manual/reference/method/Bulk.find/