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

时间:2015-06-15 14:47:25

标签: rethinkdb

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 个答案:

答案 0 :(得分:10)

您可以使用update命令和filter来过滤数组中的元素,然后传递给update

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

基本上,您将使用过滤后的数组覆盖things

相关问题