How do I removed a particular item from a embedded array in RethinkDB?

1.7k Views Asked by At

given sample data like:

{
   'id': 1,
   'things': [{'name': 'a'},{'name': 'b'},{'name': 'c'}]
}

how do I update the document removing the array item with name of 'b' from the embedded array?

r.table('test')
.get(1)
.update({things: r.row('things')????});
1

There are 1 best solutions below

0
On BEST ANSWER

You can use the update command along with filter to filter the elements in an array and pass to along to update.

r.table('30848200').get(1).update(function (row)  {
  return {
    'things': row('things')
      .filter(function (item) { return item('name').ne('b') })
  }
})

Basically, you'll be overwriting things with the filtered array.