nedb
nedb copied to clipboard
update nested array
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
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