Rethinkdb 从数组中删除字符串

Rethinkdb remove string from array

给定如下数组和数据结构,我想从 table 字段 tags。我找到了更改的解决方案,并尝试使用 deleteAt,但出现 indexesOf is not a function 错误。

var removeTags = ["val1", "val3"];

{
  name: "test1",
  tags: ["val1", "val2", "val3", "val4", "val5"]
}

所以我应该剩下:

{
  name: "test1",
  tags: ["val2", "val4", "val5"]
}

到目前为止我的代码:

var removeTags = ["val1", "val2"]
r.db('test').table('data').get('test1').update(function(row) {
  return row('tags').indexesOf(function(rl) {
    return r.expr(removeTags).contains(rl)
  })(0).do(function(idx) {
    return {
      roles: row('tags').deleteAt(idx)
    }
  })
});

这是我用作参考的question/answer。任何帮助将不胜感激,非常感谢!

没关系,我找到了答案,而且比我想象的要容易得多,我把事情搞得太复杂了!

var removeTags = ['val1', 'val2'];
r.db('test').table('data').get('test1')
  .update({tags: r.row('tags').difference(removeTags)});

总之,希望对大家有所帮助