Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.
Menu Docs

Bulk.getOperations() (método mongosh)

Bulk.getOperations()

Retorna uma matriz de operações de gravação executadas por Bulk.execute(). As operações de gravação retornadas estão em grupos conforme determinado pelo MongoDB para execução. Para obter informações sobre como o MongoDB agrupa a lista de operações de gravação em massa, consulte Comportamento Bulk.execute().

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

Esse comando está disponível em implantações hospedadas nos seguintes ambientes:

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

Observação

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

Embora o método retorne todas as 1500 operações na array retornada, esta página omite alguns dos resultados por brevidade.

[
{
"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 }
]
}
]

A matriz contém documentos com os seguintes campos:

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

Especifica o tipo de operações de gravação.

batchType
(operação)

1

Insert

2

Update

3

Remover

operations

Array de documentos que contêm os detalhes da operação.