The key of the array to search
The callback function to find the element
The callback function to update the found element
Optionaloptions: methodOptionsThe options to use
A promise if the driver is async, otherwise the updated element or undefined if not found
const db = new GoodDB(new JSONDriver({
path: './database.json'
}));
db.findAndUpdate('users',
(user) => user.id === 1,
(user) => { user.name = 'Updated Name'; return user; }
);
const db = new GoodDB(new MongoDBDriver({
uri: "..."
}));
await db.connect();
await db.findAndUpdate('users',
(user) => user.id === 1,
(user) => { user.name = 'Updated Name'; return user; }
);
Find a value in an array and update it