Bulk.getOperations()Devuelve un arreglo de operaciones de escritura ejecutadas a través de
Bulk.execute(). Las operaciones de escritura devueltas se agrupan como lo determina MongoDB para su ejecución. Para obtener información sobre cómo MongoDB agrupa la lista de operaciones de escritura masiva, consulte el comportamiento de Bulk.execute().Only use
Bulk.getOperations()after aBulk.execute(). CallingBulk.getOperations()before you callBulk.execute()will result in an incomplete list.
Compatibilidad
Este comando está disponible en implementaciones alojadas en los siguientes entornos:
- MongoDB Atlas: El servicio totalmente gestionado para implementaciones de MongoDB en la nube
Nota
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
Ejemplo
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();
El método devuelve una matriz con las operaciones ejecutadas. La salida muestra que MongoDB dividió las operaciones getOperations() en 2 grupos, uno con 1000 operaciones y otro 500 con. Para obtener información sobre cómo MongoDB agrupa la lista de operaciones de escritura masiva, consulte el comportamiento de Bulk.execute().
Aunque el método devuelve las 1500 operaciones en el arreglo devuelto, esta página omite algunos de los resultados por brevedad.
[ { "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 } ] } ]
Campos devueltos
El arreglo contiene documentos con los siguientes campos:
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.
Tip