@@ -45,7 +45,7 @@ export interface DeleteManyResult {
4545}
4646
4747/**
48- * Result returned when updating multiple entities via a query.
48+ * Result returned when updating multiple entities using a query.
4949 */
5050export interface UpdateManyResult {
5151 /** Whether the operation was successful. */
@@ -307,6 +307,11 @@ export interface EntityHandler<T = any> {
307307 * Updates a record by ID with the provided data. Only the fields
308308 * included in the data object will be updated.
309309 *
310+ * To update a single record by ID, use this method. To apply the same
311+ * update to many records matching a query, use {@linkcode updateMany | updateMany()}.
312+ * To update multiple specific records with different data each, use
313+ * {@linkcode bulkUpdate | bulkUpdate()}.
314+ *
310315 * @param id - The unique identifier of the record to update.
311316 * @param data - Object containing the fields to update.
312317 * @returns Promise resolving to the updated record.
@@ -392,29 +397,39 @@ export interface EntityHandler<T = any> {
392397 bulkCreate ( data : Partial < T > [ ] ) : Promise < T [ ] > ;
393398
394399 /**
395- * Updates multiple records matching a query using a MongoDB update operator .
400+ * Applies the same update to all records that match a query .
396401 *
397- * Applies the same update operation to all records matching the query.
398- * The `data` parameter must contain one or more MongoDB update operators
399- * (e.g., `$set`, `$inc`, `$push`). Multiple operators can be combined in a
400- * single call, but each field may only appear in one operator.
402+ * Use this when you need to make the same change across all records that
403+ * match specific criteria. For example, you could set every completed order
404+ * to "archived", or increment a counter on all active users.
401405 *
402- * Results are batched in groups of up to 500 — when `has_more` is `true`
406+ * Results are batched in groups of up to 500. When `has_more` is `true`
403407 * in the response, call `updateMany` again with the same query to update
404- * the next batch.
405- *
406- * @param query - Query object to filter which records to update. Records matching all
407- * specified criteria will be updated.
408- * @param data - Update operation object containing one or more MongoDB update operators.
408+ * the next batch. Make sure the query excludes already-updated records
409+ * so you don't re-process the same entities on each iteration. For
410+ * example, filter by `status: 'pending'` when setting status to `'processed'`.
411+ *
412+ * To update a single record by ID, use {@linkcode update | update()} instead. To update
413+ * multiple specific records with different data each, use {@linkcode bulkUpdate | bulkUpdate()}.
414+ *
415+ * @param query - Query object to filter which records to update. Use field-value
416+ * pairs for exact matches, or
417+ * [MongoDB query operators](https://www.mongodb.com/docs/manual/reference/operator/query/)
418+ * for advanced filtering. Supported query operators include `$eq`, `$ne`, `$gt`,
419+ * `$gte`, `$lt`, `$lte`, `$in`, `$nin`, `$and`, `$or`, `$not`, `$nor`,
420+ * `$exists`, `$regex`, `$all`, `$elemMatch`, and `$size`.
421+ * @param data - Update operation object containing one or more
422+ * [MongoDB update operators](https://www.mongodb.com/docs/manual/reference/operator/update/).
409423 * Each field may only appear in one operator per call.
410- * Supported operators: `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`,
411- * `$currentDate`, `$addToSet`, `$push`, `$pull`.
424+ * Supported update operators include `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`,
425+ * `$currentDate`, `$addToSet`, `$push`, and `$pull`.
412426 * @returns Promise resolving to the update result.
413427 *
414428 * @example
415429 * ```typescript
416- * // Set status to 'archived' for all completed records
417- * const result = await base44.entities.MyEntity.updateMany(
430+ * // Basic usage
431+ * // Archive all completed orders
432+ * const result = await base44.entities.Order.updateMany(
418433 * { status: 'completed' },
419434 * { $set: { status: 'archived' } }
420435 * );
@@ -423,20 +438,34 @@ export interface EntityHandler<T = any> {
423438 *
424439 * @example
425440 * ```typescript
426- * // Combine multiple operators in a single call
427- * const result = await base44.entities.MyEntity.updateMany(
441+ * // Multiple query operators
442+ * // Flag urgent items that haven't been handled yet
443+ * const result = await base44.entities.Task.updateMany(
444+ * { priority: { $in: ['high', 'critical'] }, status: { $ne: 'done' } },
445+ * { $set: { flagged: true } }
446+ * );
447+ * ```
448+ *
449+ * @example
450+ * ```typescript
451+ * // Multiple update operators
452+ * // Close out sales records and bump the view count
453+ * const result = await base44.entities.Deal.updateMany(
428454 * { category: 'sales' },
429455 * { $set: { status: 'done' }, $inc: { view_count: 1 } }
430456 * );
431457 * ```
432458 *
433459 * @example
434460 * ```typescript
435- * // Handle batched updates for large datasets
461+ * // Batched updates
462+ * // Process all pending items in batches of 500.
463+ * // The query filters by 'pending', so updated records (now 'processed')
464+ * // are automatically excluded from the next batch.
436465 * let hasMore = true;
437466 * let totalUpdated = 0;
438467 * while (hasMore) {
439- * const result = await base44.entities.MyEntity .updateMany(
468+ * const result = await base44.entities.Job .updateMany(
440469 * { status: 'pending' },
441470 * { $set: { status: 'processed' } }
442471 * );
@@ -445,30 +474,48 @@ export interface EntityHandler<T = any> {
445474 * }
446475 * ```
447476 */
448- updateMany ( query : Partial < T > , data : Record < string , Record < string , any > > ) : Promise < UpdateManyResult > ;
477+ updateMany (
478+ query : Partial < T > ,
479+ data : Record < string , Record < string , any > > ,
480+ ) : Promise < UpdateManyResult > ;
449481
450482 /**
451- * Updates multiple records in a single request, each with its own update data.
483+ * Updates the specified records in a single request, each with its own data.
484+ *
485+ * Use this when you already know which records to update and each one needs
486+ * different field values. For example, you could update the status and amount
487+ * on three separate invoices in one call.
452488 *
453- * Unlike `updateMany` which applies the same update to all matching records,
454- * `bulkUpdate` allows different updates for each record. Each item in the
455- * array must include an `id` field identifying which record to update.
489+ * You can update up to 500 records per request.
456490 *
457- * **Note:** Maximum 500 items per request.
491+ * To apply the same update to all records matching a query, use
492+ * {@linkcode updateMany | updateMany()}. To update a single record by ID, use
493+ * {@linkcode update | update()}.
458494 *
459- * @param data - Array of update objects (max 500). Each object must have an `id` field
460- * and any number of fields to update.
461- * @returns Promise resolving to an array of updated records.
495+ * @param data - Array of objects to update. Each object must contain an `id` field identifying which record to update and any fields to change.
496+ * @returns Promise resolving to an array of the updated records.
462497 *
463498 * @example
464499 * ```typescript
465- * // Update multiple records with different data
466- * const updated = await base44.entities.MyEntity.bulkUpdate([
467- * { id: 'entity-1', status: 'paid', amount: 999 },
468- * { id: 'entity-2', status: 'cancelled' },
469- * { id: 'entity-3', name: 'Renamed Item' }
500+ * // Basic usage
501+ * // Update three invoices with different statuses and amounts
502+ * const updated = await base44.entities.Invoice.bulkUpdate([
503+ * { id: 'inv-1', status: 'paid', amount: 999 },
504+ * { id: 'inv-2', status: 'cancelled' },
505+ * { id: 'inv-3', amount: 450 }
470506 * ]);
471507 * ```
508+ *
509+ * @example
510+ * ```typescript
511+ * // More than 500 items
512+ * // Reassign each task to a different owner in batches
513+ * const allUpdates = reassignments.map(r => ({ id: r.taskId, owner: r.newOwner }));
514+ * for (let i = 0; i < allUpdates.length; i += 500) {
515+ * const batch = allUpdates.slice(i, i + 500);
516+ * await base44.entities.Task.bulkUpdate(batch);
517+ * }
518+ * ```
472519 */
473520 bulkUpdate ( data : ( Partial < T > & { id : string } ) [ ] ) : Promise < T [ ] > ;
474521
0 commit comments