Saturday, 15 April 2017

lowdb: update record at index N

I'm using lowdb (https://github.com/typicode/lowdb) with a persistent storage (file-async):

const low = require('lowdb');
const db = low('db.json', {storage: require('lowdb/lib/storages/file-async')});
db.defaults({inputs: []}).value();

From a client I receive this object:

var data = {
  "idx": 1,
  "item": { "Name": "blabla", "Surname": "bleble" }
}

I want to update the record number idx with the new information received. This doesn't update anything:

if (data.idx < db.get("inputs").size()) {
    db.get("inputs").nth(data.idx)
        .assign(data.item)
        .write();
}

In my actual data I have more than 2 items.



via Mark

No comments:

Post a Comment