nedb icon indicating copy to clipboard operation
nedb copied to clipboard

update nested array

Open dcrystalj opened this issue 5 years ago • 1 comments

if i have dataset like this

{
  "_id": "abcd1234",
  "name": "randomStuff",
  "list": [
    {
      "name": "the first element",
      "value": "1234"
    },
    {
      "name": "the second element",
      "value": "5678"
    }
  ]
}

I cannot update "the first element" directly.

For example

db.update({_id: 'abcd1234'}, {$pull: {'list.value': 1234}}, {}, (err) => {
  console.log(err);
});

is not possible. instead i have to query element first. to get

const find =   {
      "name": "the first element",
      "value": "1234"
    },

which is then used as object to remove.

db.update({_id: 'abcd1234'}, {$pull: {'list': find}}, {}, (err) => {
  console.log(err);
});

proposal

make update param to accept nested queries

dcrystalj avatar Jun 15 '19 10:06 dcrystalj

I don't want to write a long answer explaining how I solved it, but take a look at my post here for how I solved it: https://github.com/louischatriot/nedb/issues/608

fexell avatar Aug 23 '19 21:08 fexell