Hello. I have the following code:
static async updateById (id, update = {}) {
const devices = await DeviceModel.find();
const deviceIndex = devices.findIndex(d => d.id === id)
if (deviceIndex === -1) throw new Error('device not found')
devices[deviceIndex] = update;
await Device.db.update('devices', devices)
}
What I want to know is that to put on the last line of the function. I need to replace the “Device.db.update(‘devices’, devices)” with actual working code.
What I’m trying to do is overwrite the current collection with a new array of documents.