AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

Bulk.getOperations()(mongoshメソッド)

Bulk.getOperations()

Bulk.execute()を通じて実行された書き込み操作の配列を返します。 返される書込み (write) 操作は、実行用 MongoDB によって決定されたグループに入れられます。 MongoDB が一括書き込み操作のリストをグループ化する方法については、「 Bulk.execute() の動作 」を参照してください。

Only use Bulk.getOperations() after a Bulk.execute(). Calling Bulk.getOperations() before you call Bulk.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 グループに分割したことが示されています。1 つは1000 操作、もう 1 つは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 }
]
}
]

配列には、次のフィールドを持つドキュメントが含まれています。

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

書込み (write) 操作のタイプを指定します。

batchType
操作

1

Insert

2

Update

3

削除

operations

操作の詳細を含むドキュメントの配列。