From this question I can find all objects in my table where a value occurs in a field that is an array. Now I need to delete that value from that field, for all objects in that table.
For example, suppose an events
table, with objects:
{ people: ['John', 'Bob', 'Sue'] }
{ people: ['Harry', 'Sue', 'Jim'] }
{ people: ['John', 'Bob', 'Elaine'] }
{ people: ['Jim', 'Bob', 'Sue'] }
Suppose I want to delete 'Sue' from the people
field for all objects.
How is this done with Dexie?
Adding the following code in an async function would do it:
await db.events.where('people').equals('Sue').modify(x => {
// This callback is run for every match.
// Here you can modify the people property to remove Sue from it:
x.people = x.people.filter(p => p !== 'Sue');
});
Note: Assume the schema is indexing 'people' with multiEntry index:
const db = new Dexie("testdb");
db.version(3).stores({
events: 'id, *people'
});
References:
Could you maybe elaborate on your answer a bit more?
Thanks David F., that's very helpful to me. I upvoted. @Twenty, this link may be helpful: dexie.org/docs/Collection/Collection.modify() Personally, I appreciate a solid answer even if it is terse, and a solid, prompt answer on a weekend is IMO worthy of an upvote.
Sorry for short answer. Was doing it from mobile before going to bed. But the reference to Collection.modify() that David Burson wrote should explain it together with the reference for MultiEntry index: dexie.org/docs/MultiEntry-Index.