如何从 RethinkDB 的嵌入式数组中删除特定项目?

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

给定样本数据,如:

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

如何更新文档,从嵌入数组中删除名称为 'b' 的数组项?

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

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

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

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