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

1

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')????});
Anatolian answered 15/6, 2015 at 14:47 Comment(0)
E
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.

Eparchy answered 15/6, 2015 at 17:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.