From 3ad163dc1dd8398d59b7d421f6c19c42b487e566 Mon Sep 17 00:00:00 2001 From: Luc Vidal Date: Tue, 28 Jul 2026 18:54:30 +0200 Subject: [PATCH] feat: update doc to mention NO_UPDATE --- README.md | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b0ff53e..cef94b9 100644 --- a/README.md +++ b/README.md @@ -143,12 +143,34 @@ new MongoBulkDataMigration({ collectionName: 'scores', projection: { scoreA: 1, scoreB: 1 }, query: FETCH_ALL, - update: (doc) => { + update: (doc) => ({ $set: { - total: doc.scoreA + doc.scoreB; - } + total: doc.scoreA + doc.scoreB, + }, + }), +}); +``` + +### Conditional update on documents + +This migration will update documents depending on an external condition. +Return the `NO_UPDATE` symbol to declare no update is needed. + +```ts +import { MongoBulkDataMigration, NO_UPDATE } from "@360-l/mongo-bulk-data-migration"; + +new MongoBulkDataMigration({ + db, + id: 'conditional_update', + collectionName: 'scores', + query: FETCH_ALL, + update: async (doc) => { + if (! await shouldUpdate(doc)) { return NO_UPDATE; } + return { $set: { satus: "updated" } }; }, }); + +async function shouldUpdate(...) // external check ``` ### Automatic resume (`query: FETCH_ALL`)