On this page本页内容
Bulk.getOperations()
Returns an array of write operations executed through 返回通过Bulk.execute()
. Bulk.execute()
执行的写入操作数组。The returned write operations are in groups as determined by MongoDB for execution. 返回的写入操作按MongoDB确定的组执行。For information on how MongoDB groups the list of bulk write operations, see Bulk.execute() Behavior.有关MongoDB如何对批量写入操作列表进行分组的信息,请参阅Bulk.execute()
行为。
Only use 只能在Bulk.getOperations()
after a Bulk.execute()
. Bulk.execute()
之后使用Bulk.getOperations()
。Calling 在调用Bulk.getOperations()
before you call Bulk.execute()
will result in an incomplete list.Bulk.execute()
之前调用Bulk.getOperations()
将导致列表不完整。
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. getOperations()
方法返回执行了操作的数组。The output shows that MongoDB divided the operations into 2 groups, one with 1000 operations and one with 500. 输出显示MongoDB将操作分为两组,一组有1000个操作,另一组有500个操作。For information on how MongoDB groups the list of bulk write operations, see Bulk.execute() Behavior有关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 } ] } ]
The array contains documents with the following fields:数组包含具有以下字段的文档:
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
.0
的originalZeroIndex
值。
batchType
Specifies the write operations type.指定写入操作类型。
batchType | |
---|---|
1 | Insert |
2 | Update |
3 | Remove |