Table.bulkUpdate()
Since v4.0.1-alpha.6
Syntax
await table.bulkUpdate([
{
key: key1,
changes: {
"keyPath1": newValue1,
"keyPath2": newValue2,
...
}
},
{
key: key2,
changes: {
"keyPathA": newValueA,
"keyPathB": newValueB,
...
}
},
...
]);
Parameters
key | Primary key of the object to update |
changes | An object where each key is a property name or path and its value is the value to set |
Remarks
This method is the bulk-version of Table.update() such that it accepts an array of keys/changes instead of a single key and changes-object.
This method will update objects with given keys using given update-specifications (changes) if the keys are found. If a key is not found, its corresponding changes wont be applied but the method will still succeed. The return value indicates how many keys were found (and updated).
The UpdateSpec
provided in changes
prop of each item can specify individual properties to be updated or deleted. Existing properties will be updated and non-existing properties will be added (if the row pointed out by the key exists). If the value provided is explicitly set to undefined, the property will be deleted.
Array properties follow the same keyPath pattern as object properties - using number as parts of the property name, such as tags.0
, tags.1
etc, see sample below.
Sample (TypeScript)
import Dexie, { type EntityTable } from 'dexie';
interface Contact {
id: number;
name: string;
tags: string[];
address: {
city: string;
street: string;
streetNo: number;
}
}
const db = new Dexie('contactDB') as Dexie & {
contacts: EntityTable<Contact, 'id'>;
// (The 4.x EntityTable<T> can make a the primary key optional on
// add/bulkAdd operations)
};
db.version(1).stores({
contacts: '++id, name, *tags, address.city'
});
// ...assuming here that you have populated your DB with some data
// before running the following call:
await db.friends.bulkUpdate([
// Update "name" property of contact with id 2:
{
key: 2,
changes: {
name: "Foo Barsson",
}
},
// Update nested property "address.streetNo" of contact with id 1:
{
key: 1,
changes: {
"address.streetNo": 2
}
},
// Replace entire "address" property of contact with id 3:
{
key: 3,
changes: {
address: {
city: "Stockholm".
street: "Sveavägen",
streetNo: 18
}
}
},
// Delete the nested property "address.city" of contact with id 5:
{
key: 5,
"address.city": undefined
},
// Add tags to contact with id 18:
{
key: 18,
tags: ["close-friend", "family"]
},
// Update tag[1] of contact with id 33:
{
key: 33,
"tags.1": "enemy"
}
]);
Sample (Plain JS)
import Dexie from 'dexie';
const db = new Dexie('contactDB');
db.version(1).stores({
contacts: '++id, name, *tags, address.city'
});
// ...assuming here that you have populated your DB with some data
// before running the following call:
await db.friends.bulkUpdate([
// Update "name" property of contact with id 2:
{
key: 2,
changes: {
name: "Foo Barsson",
}
},
// Update nested property "address.streetNo" of contact with id 1:
{
key: 1,
changes: {
"address.streetNo": 2
}
},
// Replace entire "address" property of contact with id 3:
{
key: 3,
changes: {
address: {
city: "Stockholm".
street: "Sveavägen",
streetNo: 18
}
}
},
// Delete the nested property "address.city" of contact with id 5:
{
key: 5,
"address.city": undefined
},
// Add tags to contact with id 18:
{
key: 18,
tags: ["close-friend", "family"]
},
// Update tag[1] of contact with id 33:
{
key: 33,
"tags.1": "enemy"
}
]);
Return Value
Promise<number>
The method returns the number of matching rows that were updated. A row is counted when a given key is found in the table, no matter if the update modifies the value to something that differs or not.
Errors
If some operations fail, bulkUpdate()
will return a rejected Promise with a
Dexie.BulkError referencing the failures.
See Also
Table of Contents
- API Reference
- Access Control in Dexie Cloud
- Add demo users
- Add public data
- Authentication in Dexie Cloud
- Best Practices
- Building Addons
- Collection
- Collection.and()
- Collection.clone()
- Collection.count()
- Collection.delete()
- Collection.desc()
- Collection.distinct()
- Collection.each()
- Collection.eachKey()
- Collection.eachPrimaryKey()
- Collection.eachUniqueKey()
- Collection.filter()
- Collection.first()
- Collection.keys()
- Collection.last()
- Collection.limit()
- Collection.modify()
- Collection.offset()
- Collection.or()
- Collection.primaryKeys()
- Collection.raw()
- Collection.reverse()
- Collection.sortBy()
- Collection.toArray()
- Collection.uniqueKeys()
- Collection.until()
- Compound Index
- Consistency in Dexie Cloud
- Consistent add() operator
- Consistent remove() operator
- Consistent replacePrefix() operator
- Consuming Dexie as a module
- Custom Emails in Dexie Cloud
- DBCore
- DBCoreAddRequest
- DBCoreCountRequest
- DBCoreCursor
- DBCoreDeleteRangeRequest
- DBCoreDeleteRequest
- DBCoreGetManyRequest
- DBCoreGetRequest
- DBCoreIndex
- DBCoreKeyRange
- DBCoreMutateRequest
- DBCoreMutateResponse
- DBCoreOpenCursorRequest
- DBCorePutRequest
- DBCoreQuery
- DBCoreQueryRequest
- DBCoreQueryResponse
- DBCoreRangeType
- DBCoreSchema
- DBCoreTable
- DBCoreTableSchema
- DBCoreTransaction
- DBCoreTransactionMode
- DBPermissionSet
- Deprecations
- Derived Work
- Design
- Dexie Cloud API
- Dexie Cloud API Limits
- Dexie Cloud Best Practices
- Dexie Cloud CLI
- Dexie Cloud Docs
- Dexie Cloud REST API
- Dexie Cloud Web Hooks
- Dexie Constructor
- Dexie.AbortError
- Dexie.BulkError
- Dexie.ConstraintError
- Dexie.DataCloneError
- Dexie.DataError
- Dexie.DatabaseClosedError
- Dexie.IncompatiblePromiseError
- Dexie.InternalError
- Dexie.InvalidAccessError
- Dexie.InvalidArgumentError
- Dexie.InvalidStateError
- Dexie.InvalidTableError
- Dexie.MissingAPIError
- Dexie.ModifyError
- Dexie.NoSuchDatabaseErrorError
- Dexie.NotFoundError
- Dexie.Observable
- Dexie.Observable.DatabaseChange
- Dexie.OpenFailedError
- Dexie.PrematureCommitError
- Dexie.QuotaExceededError
- Dexie.ReadOnlyError
- Dexie.SchemaError
- Dexie.SubTransactionError
- Dexie.Syncable
- Dexie.Syncable.IDatabaseChange
- Dexie.Syncable.IPersistentContext
- Dexie.Syncable.ISyncProtocol
- Dexie.Syncable.StatusTexts
- Dexie.Syncable.Statuses
- Dexie.Syncable.registerSyncProtocol()
- Dexie.TimeoutError
- Dexie.TransactionInactiveError
- Dexie.UnknownError
- Dexie.UnsupportedError
- Dexie.UpgradeError()
- Dexie.VersionChangeError
- Dexie.VersionError
- Dexie.[table]
- Dexie.addons
- Dexie.async()
- Dexie.backendDB()
- Dexie.close()
- Dexie.currentTransaction
- Dexie.debug
- Dexie.deepClone()
- Dexie.defineClass()
- Dexie.delByKeyPath()
- Dexie.delete()
- Dexie.derive()
- Dexie.events()
- Dexie.exists()
- Dexie.extend()
- Dexie.fakeAutoComplete()
- Dexie.getByKeyPath()
- Dexie.getDatabaseNames()
- Dexie.hasFailed()
- Dexie.ignoreTransaction()
- Dexie.isOpen()
- Dexie.js
- Dexie.name
- Dexie.on()
- Dexie.on.blocked
- Dexie.on.close
- Dexie.on.error
- Dexie.on.populate
- Dexie.on.populate-(old-version)
- Dexie.on.ready
- Dexie.on.storagemutated
- Dexie.on.versionchange
- Dexie.open()
- Dexie.override()
- Dexie.semVer
- Dexie.setByKeyPath()
- Dexie.shallowClone()
- Dexie.spawn()
- Dexie.table()
- Dexie.tables
- Dexie.transaction()
- Dexie.transaction()-(old-version)
- Dexie.use()
- Dexie.verno
- Dexie.version
- Dexie.version()
- Dexie.vip()
- Dexie.waitFor()
- DexieCloudOptions
- DexieError
- Docs Home
- Download
- EntityTable
- Export and Import Database
- Get started with Dexie in Angular
- Get started with Dexie in React
- Get started with Dexie in Svelte
- Get started with Dexie in Vue
- Hello World
- How To Use the StorageManager API
- Inbound
- IndexSpec
- Indexable Type
- IndexedDB on Safari
- Invite
- Member
- Migrating existing DB to Dexie
- MultiEntry Index
- PersistedSyncState
- Privacy Policy
- Promise
- Promise.PSD
- Promise.catch()
- Promise.finally()
- Promise.on.error
- Promise.onuncatched
- Questions and Answers
- Realm
- Releasing Dexie
- Road Map
- Road Map: Dexie 5.0
- Road Map: Dexie Cloud
- Role
- Run Dexie Cloud on Own Servers
- Sharding and Scalability
- Simplify with yield
- Support Ukraine
- SyncState
- Table
- Table Schema
- Table.add()
- Table.bulkAdd()
- Table.bulkDelete()
- Table.bulkGet()
- Table.bulkPut()
- Table.bulkUpdate()
- Table.clear()
- Table.count()
- Table.defineClass()
- Table.delete()
- Table.each()
- Table.filter()
- Table.get()
- Table.hook('creating')
- Table.hook('deleting')
- Table.hook('reading')
- Table.hook('updating')
- Table.limit()
- Table.mapToClass()
- Table.name
- Table.offset()
- Table.orderBy()
- Table.put()
- Table.reverse()
- Table.schema
- Table.toArray()
- Table.toCollection()
- Table.update()
- Table.where()
- The main limitations of IndexedDB
- Transaction
- Transaction.abort()
- Transaction.on.abort
- Transaction.on.complete
- Transaction.on.error
- Transaction.table()
- Tutorial
- Typescript
- Typescript (old)
- Understanding the basics
- UserLogin
- Version
- Version.stores()
- Version.upgrade()
- WhereClause
- WhereClause.above()
- WhereClause.aboveOrEqual()
- WhereClause.anyOf()
- WhereClause.anyOfIgnoreCase()
- WhereClause.below()
- WhereClause.belowOrEqual()
- WhereClause.between()
- WhereClause.equals()
- WhereClause.equalsIgnoreCase()
- WhereClause.inAnyRange()
- WhereClause.noneOf()
- WhereClause.notEqual()
- WhereClause.startsWith()
- WhereClause.startsWithAnyOf()
- WhereClause.startsWithAnyOfIgnoreCase()
- WhereClause.startsWithIgnoreCase()
- db.cloud.configure()
- db.cloud.currentUser
- db.cloud.currentUserId
- db.cloud.events.syncComplete
- db.cloud.invites
- db.cloud.login()
- db.cloud.logout()
- db.cloud.options
- db.cloud.permissions()
- db.cloud.persistedSyncState
- db.cloud.roles
- db.cloud.schema
- db.cloud.sync()
- db.cloud.syncState
- db.cloud.userInteraction
- db.cloud.usingServiceWorker
- db.cloud.version
- db.cloud.webSocketStatus
- db.members
- db.realms
- db.roles
- db.syncable.connect()
- db.syncable.delete()
- db.syncable.disconnect()
- db.syncable.getOptions()
- db.syncable.getStatus()
- db.syncable.list()
- db.syncable.on('statusChanged')
- db.syncable.setFilter()
- dexie-cloud-addon
- dexie-react-hooks
- liveQuery()
- unhandledrejection-event
- useLiveQuery()
- useObservable()
- usePermissions()