对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

Bulk.getOperations()(mongosh方法)

Bulk.getOperations()

返回通过Bulk.execute()执行的写入操作的数组。 返回的写入操作按 MongoDB 确定的分组执行。 有关 MongoDB 如何对批量写入操作列表进行分组的信息,请参阅Bulk.execute() 行为。

Only use Bulk.getOperations() after a Bulk.execute(). Calling Bulk.getOperations() before you call Bulk.execute() will result in an incomplete list.

此命令可用于以下环境中托管的部署:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

The following initializes a Bulk() operations builder on the items collection, adds a series of write operations, executes the operations, and then calls getOperations() on the bulk builder object:

var bulk = db.items.initializeUnorderedBulkOp();
for (var i = 1; i <= 1500; i++) {
bulk.insert( { x: i } );
}
bulk.execute();
bulk.getOperations();

The getOperations() method returns an array with the operations executed. The output shows that MongoDB divided the operations into 2 groups, one with 1000 operations and one with 500. For information on how MongoDB groups the list of bulk write operations, see Bulk.execute() Behavior

虽然该方法会返回返回数组中的所有 1500 个操作,但为了简洁起见,本页省略了一些结果。

[
{
"originalZeroIndex" : 0,
"batchType" : 1,
"operations" : [
{ "_id" : ObjectId("53a8959f1990ca24d01c6165"), "x" : 1 },
... // Content omitted for brevity
{ "_id" : ObjectId("53a8959f1990ca24d01c654c"), "x" : 1000 }
]
},
{
"originalZeroIndex" : 1000,
"batchType" : 1,
"operations" : [
{ "_id" : ObjectId("53a8959f1990ca24d01c654d"), "x" : 1001 },
... // Content omitted for brevity
{ "_id" : ObjectId("53a8959f1990ca24d01c6740"), "x" : 1500 }
]
}
]

该数组包含具有以下字段的文档:

originalZeroIndex

Specifies the order in which the operation was added to the bulk operations builder, based on a zero index; e.g. first operation added to the bulk operations builder will have originalZeroIndex value of 0.

batchType

指定写入操作类型。

batchType
操作

1

Insert

2

Update

3

删除

operations

包含操作详细信息的文档数组。

给本页内容打分