Bulk.getOperations()返回通过
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.
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
例子
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();
getOperations()方法返回一个包含已执行操作的大量。输出显示MongoDB将操作分为2 组,一组包含1000 操作,一组包含500 操作。有关MongoDB如何对批量写入操作列表进行分组的信息,请参阅 Bulk.execute() 行为
虽然该方法会返回返回数组中的所有 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 } ] } ]
返回的字段
该数组包含具有以下字段的文档:
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.