7

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')????});
Samuel Goldenbaum
  • 18,391
  • 17
  • 66
  • 104

1 Answers1

11

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.

Jorge Silva
  • 4,574
  • 1
  • 23
  • 42