Warm tip: This article is reproduced from stackoverflow.com, please click
indexeddb updates bulkupdate dexie

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

发布于 2020-04-19 09:32:45

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?

Questioner
David Burson
Viewed
59
David Fahlander 2020-02-05 07:46
myTable.where({location: 'Paris'}).modify({location: ''})

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