Docs Menu

Bulk.find.updateOne()

Tip

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

Bulk.find.updateOne(<update>)

Adds a single document update operation to a bulk operations list.

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
タイプ
説明

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

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

A replacement document

Contains only field and value pairs.

Bulk.find.replaceOne() も参照してください。

Update document

更新演算子式のみが含まれます。

Aggregation Pipeline

次の集計ステージのみが含まれます。

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

The sum of the associated <query> document from the Bulk.find() and the update document must be less than or equal to the maximum BSON document size.

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

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

注意

このコマンドは、すべての MongoDB Atlas クラスターでサポートされています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。

If the <update> document contains only update operator expressions, as in:

{
$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();