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

Bulk.find.updateOne()(mongoshメソッド)

Tip

MongoDB は、一括書き込み操作を実行するための Mongo.bulkWrite() メソッドも提供します。

Bulk.find.updateOne(<update>)

一括操作リストに 1 つのドキュメントのアップデート操作を追加します。

Use the Bulk.find() method to specify the condition that determines which document to update. The Bulk.find.updateOne() method limits the update to a single document. To update multiple documents, see Bulk.find.update().

Bulk.find.updateOne() は、次のパラメーターを受け入れます。

Parameter
タイプ
説明

ドキュメントまたはパイプライン

適用される変更内容。次のいずれかになります。

update 変更パラメーターの詳細については、db.collection.updateOne() のリファレンス ページを参照してください。

Bulk.find() からの関連 <query> ドキュメントと更新ドキュメントの合計は、BSON ドキュメントの最大サイズ以下である必要があります。

このコマンドは、次の環境でホストされている配置で使用できます。

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

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

<update>ドキュメントに更新演算子式のみが含まれている場合は、次のようになります。

{
$set: { status: "D" },
$inc: { points: 2 }
}

Then, Bulk.find.updateOne() updates only the corresponding fields, status and points, in the document.

The following example initializes a Bulk() operations builder for the items collection, and adds various updateOne() operations to the list of operations.

var bulk = db.items.initializeUnorderedBulkOp();
bulk.find( { status: "D" } ).updateOne( { $set: { status: "I", points: "0" } } );
bulk.execute();

更新メソッドは集計パイプラインを受け入れることができます。 たとえば、次の例では次のものが使用されています。

  • $set ステージは、$set 更新演算子式と同様に動作します。

  • 集計変数 NOW は現在の日時を解決し、$currentDate 更新演算子式と同様に動作します。集計変数にアクセスするには、変数の前に二重ドル記号 $$ を付け、引用符で囲みます。

var bulk = db.items.initializeUnorderedBulkOp();
bulk.find( { status: "P" } ).updateOne(
[
{ $set: { points: 0, lastModified: "$$NOW" } }
]
);
bulk.execute();
このページを評価