Bulk.getOperations()Returns an array of write operations executed through返回通过Bulk.execute(). The returned write operations are in groups as determined by MongoDB for execution. For information on how MongoDB groups the list of bulk write operations, see Bulk.execute() Behavior.Bulk.execute()执行的写入操作数组。返回的写入操作按MongoDB确定的组执行。有关MongoDB如何对批量写入操作列表进行分组的信息,请参阅Bulk.execute()行为。Only use仅在Bulk.getOperations()after aBulk.execute(). CallingBulk.getOperations()before you callBulk.execute()will result in an incomplete list.Bulk.execute()之后使用Bulk.getOperations()。在调用Bulk.execute()之前调用Bulk.getOperations()将导致列表不完整。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Note
This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
Example示例
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:items集合上的Bulk()操作构建器,添加一系列写操作,执行这些操作,然后对Bulk构建器对象调用getOperations():
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() BehaviorgetOperations()>方法返回一个执行了操作的数组。输出显示MongoDB将操作分为2组,一组包含1000个操作,另一组包含500个操作。有关MongoDB如何对批量写入操作列表进行分组的信息,请参阅Bulk.execute()行为。
Although the method returns all 1500 operations in the returned array, this page omits some of the results for brevity.虽然该方法返回返回数组中的所有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 }
]
}
]Returned Fields返回字段
The array contains documents with the following fields:数组包含具有以下字段的文档:
originalZeroIndexSpecifies 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指定基于零索引将操作添加到批量操作生成器的顺序;例如,添加到批量操作生成器中的第一个操作的originalZeroIndexvalue of0.originalZeroIndex值为0。
batchTypeSpecifies the write operations type.指定写入操作类型。batchTypeOperation操作1 Insert 2 Update 3 Remove
operationsArray of documents that contain the details of the operation.包含操作详细信息的文档数组。