Search code examples
updatesindexeddbbulkupdatedexie

With Dexie, how to update multiple objects with a non-primary index?


I want to do something like, myTable.update({ location: 'Paris'}, { location: '' } and have all the objects in myTable that have a location of 'Paris' get changed to have location set to empty string.

location is not a primary key, so there may be any number of objects in myTable that have location = 'Paris' before executing the command, but there should be none with location = 'Paris' after executing the command.

I come from a SQL background, so this seems like a very simple, basic function for a database. But the Dexie docs for Table.update() indicate that it only supports using a primary key, and consequently can only update at most one object. Surely, there's some way to do this other than looping to make multiple calls to update the database? Some command I haven't seen? Or am I failing to understand something about NoSql databases that I should know?


Solution

  • myTable.where({location: 'Paris'}).modify({location: ''})
    

    https://dexie.org/docs/Collection/Collection.modify()